473,382 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Date and Time

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
Sep 4 '08 #1
14 1870
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".
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Sep 4 '08 #2
On Sep 4, 10:37*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
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? 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.htmand a
Date Object Methods reference as there cited.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ...
Sep 4 '08 #3
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.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 5 '08 #4
On Sep 5, 11:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Dr J R Stockton wrote:
Is that ignorance or merely perversity?

It is a request.
I don't think you two realize how embarrassing your little tiff is to
the rest of us. Please grow up, both of you.

Steve.

Sep 5 '08 #5
Steve wrote on 05 sep 2008 in comp.lang.javascript:
On Sep 5, 11:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>Dr J R Stockton wrote:
Is that ignorance or merely perversity?

It is a request.

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.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 5 '08 #6
On Sep 5, 10:46 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Steve wrote on 05 sep 2008 in comp.lang.javascript:
On Sep 5, 11:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Dr J R Stockton wrote:
Is that ignorance or merely perversity?
It is a request.
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.
Hmmmm? OK, if you say so :-)

Sep 5 '08 #7
In comp.lang.javascript message <48**************@PointedEars.de>, Fri,
5 Sep 2008 11:57:33, Thomas 'PointedEars' Lahn <Po*********@web.de>
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.
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/.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
Sep 5 '08 #8
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, <f8*******************@news.demon.co.uk>
Sep 6 '08 #9
On Sep 6, 5:54*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
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, <f806at$ail$1$8300d...@news.demon.co.uk>
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
Sep 6 '08 #10
shapper wrote:
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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Sep 7 '08 #11
In comp.lang.javascript message <fbfd9f68-c963-48df-9bb0-4a07a4bc19ab@y3
8g2000hsy.googlegroups.com>, Sat, 6 Sep 2008 16:16:21, shapper
<md*****@gmail.composted:
>Therefore I asked.

PointedEars
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.htmff.?

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.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 7 '08 #12
shapper wrote:
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....277c9f91b3fb0/

Hope this helps,

--
Bart
Sep 9 '08 #13
Bart Van der Donck wrote:
'toUTCString()' or 'toGMTString()' is probably a matter of preference.
It appears that 'toUTCString' is better.

http://developer.mozilla.org/En/Core...te/ToGMTString
http://msdn.microsoft.com/en-us/libr...82(VS.85).aspx

--
Bart
Sep 9 '08 #14
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
<ba**@nijlen.composted:
>Bart Van der Donck wrote:
>'toUTCString()' or 'toGMTString()' is probably a matter of preference.

It appears that 'toUTCString' is better.

http://developer.mozilla.org/En/Core...ence/Global_Ob
jects/Date/ToGMTString
http://msdn.microsoft.com/en-us/libr...82(VS.85).aspx
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,

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 10 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
3
by: colleen1980 | last post by:
Hi: Data in my table is in that format. How to i separate date with time. 11/9/2006 10:10:46 AM Thank You.
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.