Date and Time

S

shapper

Hello,

Is there any function to convert a Date/Time from UTC to the user
client zone and back from user client zone to UTC?

I want to store Date/Time in UTC in the database but display it in
local use Date/Time.

Thanks,
Miguel
 
T

Thomas 'PointedEars' Lahn

shapper said:
Is there any function to convert a Date/Time from UTC to the user
client zone and back from user client zone to UTC?

Probably yes. Please define "UTC" and "user client zone".


PointedEars
 
D

Dr J R Stockton

Probably yes.  Please define "UTC" and "user client zone".


Is that ignorance or merely perversity? UTC is a standard term, and
can be found in ISO/IEC 16262 with which you should be familiar (31
times, as a "word"; others as part of a method name). And "user
client zone" makes aense in English, thogh "zone" must be talen as
"region" and not "Time Zone" to be accurate.

OP : see in/via <URL:http://www.merlyn.demon.co.uk/js-dates.htm> and a
Date Object Methods reference as there cited.
 
T

Thomas 'PointedEars' Lahn

Dr said:
Is that ignorance or merely perversity?

It is a request.
UTC is a standard term, and can be found in ISO/IEC 16262 with which you
should be familiar [...]

It matters which UTC and "user client zone" format is used here.


PointedEars
 
E

Evertjan.

Steve wrote on 05 sep 2008 in comp.lang.javascript:
I don't think you two realize how embarrassing your little tiff is to
the rest of us. Please grow up, both of you.

Nonsense, only your own actions can be embarrasing on Usenet.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Fri,
5 Sep 2008 11:57:33 said:
Dr said:
Is that ignorance or merely perversity?

It is a request.
UTC is a standard term, and can be found in ISO/IEC 16262 with which you
should be familiar [...]

It matters which UTC and "user client zone" format is used here.

You wrote nothing about "format". You should answer more slowly,
allowing yourself time to think more about the question and your
possible answers.

The OP may, but does not necessarily, want to convert between strings;
my first thought was of converting, for example, the result of
new Date(Y_UTC, ... , s_UTC)
to what would have been given by
new Date(Date.UTC(Y_UTC, ... , s_UTC))
and/or /vice versa/.
 
T

Thomas 'PointedEars' Lahn

Dr said:
Thomas 'PointedEars' Lahn posted:
Dr said:
Thomas 'PointedEars' Lahn wrote:
shapper wrote:
Is there any function to convert a Date/Time from UTC to the user
client zone and back from user client zone to UTC?
Probably yes. Please define "UTC" and "user client zone".
Is that ignorance or merely perversity?
It is a request.
UTC is a standard term, and can be found in ISO/IEC 16262 with which you
should be familiar [...]
It matters which UTC and "user client zone" format is used here.

[...]
The OP may, but does not necessarily, want to convert between strings;
[...]

Therefore I asked.


PointedEars
 
S

shapper

Dr J R Stockton wrote:


Thomas 'PointedEars' Lahn posted:
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn wrote:
shapper wrote:
Is there any function to convert a Date/Time from UTC to the user
client zone and back from user client zone to UTC?
Probably yes.  Please define "UTC" and "user client zone".
Is that ignorance or merely perversity?
It is a request.
UTC is a standard term, and can be found in ISO/IEC 16262 with which you
should be familiar [...]
It matters which UTC and "user client zone" format is used here.
[...]
The OP may, but does not necessarily, want to convert between strings;
[...]

Therefore I asked.

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <[email protected]>

Hello,

I have seen this happening, a few times with me, both in CSS and
Javascript groups.

A discussion starts for nothing ... I will say what I usually say. Go
to the beach and relax ... :)

Anyway, back to what is important. First of all let me say that I am
not Javascript expert. My problem is:

On my MVC application I have a few web pages with forms which has
inputs for date and time on the following format:

"2008-09-14 23:05:37"

On my database I save all dates and times in UTC (http://www.iso.org/
iso/date_and_time_format) format.

However I need to:

1. Convert the UTC Date/Time in a form input to the Time Zone of the
user.
This should be done after the form is loaded so the value is there.

2. Convert the Date/Time string inserted by the user from its TimeZone
to UTC and replace it in the input when the form is submitted.
This way on my server side code I will get the correct Date/Time to
insert in the database.

I know this can't be done on the server side. On the server side I am
not able to get the Local Time Zone. Only UTC.

Note: When I say conversion I mean that in UTC 2008-09-13 23:10:40
might be 2008-09-14 02:10:40 ...

Thanks,
Miguel
 
D

Dr J R Stockton

In comp.lang.javascript message <fbfd9f68-c963-48df-9bb0-4a07a4bc19ab@y3
8g2000hsy.googlegroups.com>, Sat, 6 Sep 2008 16:16:21, shapper

Not comprehensibly, though; so it does not count.

I have seen this happening, a few times with me, both in CSS and
Javascript groups.

Then you should have learned by now to trim quotes, especially sigs.

On my MVC application I have a few web pages with forms which has
inputs for date and time on the following format:

"2008-09-14 23:05:37"

Unspecified time zone; inadequate data. Assumed local.

1. Convert the UTC Date/Time in a form input to the Time Zone of the
user.
This should be done after the form is loaded so the value is there.

RegExp substitute - to /, append " UTC", read with new date(String).
You can show it with the non-UTC methods, and you can generate a numeric
offset indication from getTimezoneOffset. Offset abbreviations cannot
be generated, and cannot (apart from GMT & UTC) be read cross-browser.
2. Convert the Date/Time string inserted by the user from its TimeZone
to UTC and replace it in the input when the form is submitted.

Read it with new Date and no offset indication; use the UTC methods to
generate the reply string, followed by " UTC" or "Z" or numeric form for
clarity.
This way on my server side code I will get the correct Date/Time to
insert in the database.

I know this can't be done on the server side. On the server side I am
not able to get the Local Time Zone. Only UTC.

Note: When I say conversion I mean that in UTC 2008-09-13 23:10:40
might be 2008-09-14 02:10:40 ...

Which parts of that are not demonstrated in <URL:http://www.merlyn.demon
..co.uk/js-dates.htm> ff.?

Note that it will be more efficient, user-side, to transmit/receive
date/times as milliseconds from UTC 1970.0 - and if server-side can
handle that, it will be efficient there too.


Which gives me an opportunity to ask how this might put in valid PHP?
PSEUDOCODE :
var Now = new Date( <?php echo +new Date() ?> ) // possibly


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Thomas 'PointedEars' Lahn

shapper said:
On my MVC application I have a few web pages with forms which has
inputs for date and time on the following format:

"2008-09-14 23:05:37"

Which is the "user client zone" value, I presume? OK.
On my database I save all dates and times in UTC (http://www.iso.org/
iso/date_and_time_format) format.

And I asked you to define that. In particular, how do you store UTC in your
database? There are a number of ways, including the number of milliseconds
since epoch, several time formats, and one of the standard UTC formats.

The time format you are using determines what would be the best approach to
convert from and to it.
However I need to:

1. Convert the UTC Date/Time in a form input to the Time Zone of the
user. This should be done after the form is loaded so the value
is there.

2. Convert the Date/Time string inserted by the user from its TimeZone
to UTC and replace it in the input when the form is submitted.
This way on my server side code I will get the correct Date/Time to
insert in the database.

I know this can't be done on the server side. On the server side I am
not able to get the Local Time Zone. Only UTC.

So, what have you tried already?
Note: When I say conversion I mean that in UTC 2008-09-13 23:10:40
might be 2008-09-14 02:10:40 ...

It is not helpful, though.


PointedEars
 
B

Bart Van der Donck

shapper said:
On my MVC application I have a few web pages with forms which has
inputs for date and time on the following format:

"2008-09-14 23:05:37"

On my database I save all dates and times in UTC (http://www.iso.org/
iso/date_and_time_format) format.

However I need to:

1. Convert the UTC Date/Time in a form input to the Time Zone of the
user.
   This should be done after the form is loaded so the value is there..

2. Convert the Date/Time string inserted by the user from its TimeZone
to UTC and replace it in the input when the form is submitted.
   This way on my server side code I will get the correct Date/Time to
insert in the database.

Local date to UTC:

var L = '2008-11-30 00:48:07';
alert((new Date(L.replace(/-/g,'/'))).toUTCString());

UTC to local date:

var U = '2008-06-21 22:18:36';
alert((new Date((U+' UTC').replace(/-/g,'/'))).toLocaleString());

Note that there might be different daylight saving times.
'toUTCString()' or 'toGMTString()' is probably a matter of preference.
For the conversion of date strings back into 'YYYY-MM-DD HH:MM:SS',
please see:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7277c9f91b3fb0/

Hope this helps,
 
D

Dr J R Stockton

In comp.lang.javascript message <fd03bf9e-0f47-4cff-990d-afc13269ef1c@2g
2000hsn.googlegroups.com>, Tue, 9 Sep 2008 10:26:01, Bart Van der Donck

ISO/IEC 16262 is more authoritative. It says that (initially) both
names refer to the same routine, but prefers the UTC name. However,
since UTC has Leap Seconds while GMT and JavaScript do not, toGMTString
is etymologically the better name, at least for Firefox.

The second quoted link has information which in my IE7 is false, though
it is true in FF2.0.0.16. In both browsers, the "two methods" do appear
to be one method with two names. However, the IE7 method clearly
differs from the FF2 method.

A coder should, if reading the results of such a method, allow for the
possibility of getting either GMT or UTC.

The OP should be aware that the standard requires the current-day Summer
Time rules to be applied, so a US date of 31 March should be deemed to
be in Winter Time, even if in 2006 ... or in BC 123456,
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top