470,618 Members | 1,723 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

formatting time

Ike
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
Jul 20 '05 #1
4 1093
Ike wrote:
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


var objDate = new Date(1078349279);
var strDate = objDate.toUTCString();

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/
Jul 20 '05 #2
JRS: In article <Iq*****************@newsfe3-win.server.ntli.net>, seen
in news:comp.lang.javascript, Andrew Urquhart <re***@website.in.sig>
posted at Wed, 3 Mar 2004 21:51:10 :-
Ike wrote:
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


var objDate = new Date(1078349279);
var strDate = objDate.toUTCString();


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(1078349279000) -> 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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3
In article <Iq*****************@newsfe3-win.server.ntli.net>, Andrew
Urquhart <re***@website.in.sig> writes
Ike wrote:
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
var objDate = new Date(1078349279);

!var strDate = objDate.toUTCString();

You have a plethora of methods available, just search for a list.


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

John
--
John Harris
Jul 20 '05 #4
John G Harris wrote:
Times 1000. Dates hold the number of milliseconds, not the number of
seconds.


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/
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Dimitri Furman | last post: by
4 posts views Thread by hope | last post: by
25 posts views Thread by mdh | last post: by
7 posts views Thread by L. Scott M. | last post: by
4 posts views Thread by Ken Wigle | last post: by
7 posts views Thread by christery | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.