formatting time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ike

    formatting time

    If I have an integer, like :
    1078349279

    representing seconds since the "epoch" (jan 1, 1970) is there a means in
    javascript to format that into the date and time? Thank you. Ike


  • Andrew Urquhart

    #2
    Re: formatting time

    Ike wrote:[color=blue]
    > If I have an integer, like :
    > 1078349279
    >
    > representing seconds since the "epoch" (jan 1, 1970) is there a means
    > in javascript to format that into the date and time? Thank you. Ike[/color]

    var objDate = new Date(1078349279 );
    var strDate = objDate.toUTCSt ring();

    You have a plethora of methods available, just search for a list.
    --
    Andrew Urquhart
    - FAQ: http://jibbering.com/faq
    - Archive: http://groups.google.com/groups?grou...ang.javascript
    - Reply: www.andrewu.co.uk/about/contact/


    Comment

    • Dr John Stockton

      #3
      Re: formatting time

      JRS: In article <Iqs1c.8475$x37 .4573@newsfe3-win.server.ntli .net>, seen
      in news:comp.lang. javascript, Andrew Urquhart <reply@website. in.sig>
      posted at Wed, 3 Mar 2004 21:51:10 :-[color=blue]
      >Ike wrote:[color=green]
      >> If I have an integer, like :
      >> 1078349279
      >>
      >> representing seconds since the "epoch" (jan 1, 1970) is there a means
      >> in javascript to format that into the date and time? Thank you. Ike[/color]
      >
      >var objDate = new Date(1078349279 );
      >var strDate = objDate.toUTCSt ring();[/color]

      That does assume that *his* epoch is GMT, which is no more than very
      probable. It also omits the factor of 1000 that is probably required.

      new Date(1078349279 ) -> Tue Jan 13 11:32:29 UTC 1970
      new Date(1078349279 000) -> Wed Mar 3 21:27:59 UTC 2004

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      • John G Harris

        #4
        Re: formatting time

        In article <Iqs1c.8475$x37 .4573@newsfe3-win.server.ntli .net>, Andrew
        Urquhart <reply@website. in.sig> writes[color=blue]
        >Ike wrote:[color=green]
        >> If I have an integer, like :
        >> 1078349279
        >>
        >> representing seconds since the "epoch" (jan 1, 1970) is there a means
        >> in javascript to format that into the date and time? Thank you. Ike[/color]
        >
        >var objDate = new Date(1078349279 );[/color]
        ![color=blue]
        >var strDate = objDate.toUTCSt ring();
        >
        >You have a plethora of methods available, just search for a list.[/color]

        Times 1000. Dates hold the number of milliseconds, not the number of
        seconds.

        John
        --
        John Harris

        Comment

        • Andrew Urquhart

          #5
          Re: formatting time

          John G Harris wrote:[color=blue]
          > Times 1000. Dates hold the number of milliseconds, not the number of
          > seconds.[/color]

          Indeed, thanks John and John
          --
          Andrew Urquhart
          - FAQ: http://jibbering.com/faq
          - Archive: http://groups.google.com/groups?grou...ang.javascript
          - Reply: www.andrewu.co.uk/about/contact/


          Comment

          Working...