Convert UTC to Local Time

V

vunet.us

How can I convert UTC time such as 1173451235415 to a local time I can
read? Thank you
 
S

scripts.contact

How can I convert UTC time such as 1173451235415 to a local time I can
read? Thank you

gmtDate=new Date(UTC Date)

e.g.-
alert(Date(1173451235415))
 
V

vunet.us

gmtDate=new Date(UTC Date)

e.g.-
alert(Date(1173451235415))

thank you, my problem was that 1173451235415 could not be a string.
when i parseInt(sometime), it works well. thank you very much.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
legroups.com>, Thu, 8 Mar 2007 13:53:45, (e-mail address removed)
posted:
even a string should work-
Date("1173451235415")


or +sometime
e.g
Date(+somtime)

Don't post untested code; it shows that you overestimate your ability.
In IE6 at least, Date(X) ignores the value of X. See ISO 16262
sections 15.9.2 & 15.9.2.1 which seem not to agree; ECMA-262 likewise.

Calling new Date(1173451235415) does no conversion; the digits are
converted to an IEEE Double (type Number) outside the call, and that
value is copied into the newly-created Date Object.

The default conversion from Date Object to String, and some of the
explicit Methods, convert to unspecified string forms of local
date/time.

While your answer seems to have satisfied vunet's immediate need, it
will not have taught him much.

It's a good idea to read the newsgroup and its FAQ. See below.
 
S

scripts.contact

Don't post untested code; it shows that you overestimate your ability.

that wasn't untested. I tested that before replying.
In IE6 at least, Date(X) ignores the value of X. See ISO 16262
sections 15.9.2 & 15.9.2.1 which seem not to agree; ECMA-262 likewise.


you are right. It doesn't work. It just ignores the X. I tested but i
didn't notice the date it returned was today's date.

Calling new Date(1173451235415) does no conversion; the digits are
converted to an IEEE Double (type Number) outside the call, and that
value is copied into the newly-created Date Object.

but in help, it says -
new Date(dateVal)
If a numeric value, dateVal represents the number of milliseconds in
Universal Coordinated Time between the specified date and midnight
January 1, 1970.

It alerts the correct year but not the month and date.

sorry vunet, dont use these methods. They return the wrong date.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top