www.webdeveloper.com
Results 1 to 7 of 7

Thread: Parse date into milliseconds of January 1, 1970

  1. #1
    Join Date
    Nov 2011
    Posts
    4

    Parse date into milliseconds of January 1, 1970

    Hello

    How can i parse a date into milliseconds which is in this format:

    2011-305 19:32:56.702+0000

    Date.parse(date)
    doesnt work.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,415

    Question Need more information and clarification...

    What format does that date represent?

    Year-DOY HH:MM:SS.msec

    where DOY is day of the year (1-366)?
    or March 5 of 2011?
    or May 3 or 2011?

    Ignore all information past the '+' character?

  3. #3
    Join Date
    Nov 2011
    Posts
    4
    The format goes like that:

    yyyy-DD HH:mm:ss.SSSZ

    That is
    Year-Day in year Hour in day:minute in hour:second in minute.Millisecond + Time Zone

  4. #4
    Join Date
    Nov 2011
    Posts
    4
    Argh, i could not find edit button. Yes, past the "+" can be ignored.

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,415

    Lightbulb Something to try ...

    You might try this or some variation of it based upon the form of your input...
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?p=1178319#post1178319
    
    var entryInfo = '2011-305 19:32:56.702+0000';
    
    Date.fromDayofYear= function(n, y){
        if(!y) y= new Date().getFullYear();
        var d= new Date(y, 0, 1);
        return new Date(d.setMonth(0, n));
    }
    Date.prototype.dayofYear= function(){
        var d= new Date(this.getFullYear(), 0, 0);
        return Math.floor((this-d)/8.64e+7);
    }
    
    var d=new Date().dayofYear();  // now
    alert('day# '+d+' is '+Date.fromDayofYear(d).toLocaleDateString())
    
    
    function convertDayOfYearToDate(entryInfo) {
      var info = entryInfo.split(' ');
      var yyyy_ddd = info[0].split('-');
      var y = yyyy_ddd[0];
      var d = yyyy_ddd[1];
      alert('day# '+d+' is '+Date.fromDayofYear(d,y).toLocaleDateString())
    }
    
    convertDayOfYearToDate(entryInfo);
    
    </script>
    
    </head>
    <body>
    
    </body>
    </html>
    Good Luck!

  6. #6
    Join Date
    Nov 2011
    Posts
    4
    Thank you very much, sir
    You, sir, are a genius!

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,415

    Thumbs up

    Quote Originally Posted by pelmeen10 View Post
    Thank you very much, sir
    You, sir, are a genius!
    You're most welcome.
    Happy to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles