Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with Local Time and Date

Engaged ,
Apr 02, 2008 Apr 02, 2008
Hi,

I have an application that uses now(). However, I think this function takes the time from the users computer, but the server is different. Therefore, when comparing times, it gets it all wrong.

How can I use GMT (United Kingdom) as my primary time and date format. Is there any way I can convert a date (either from the server or users computer) to read as a proper GMT time??

I have looked at the following code:

<h3>LSParseDateTime Example - returns a locale-specific date/time object</h3>
<!--- loop through a list of locales and show date values for Now()--->

<cfdump var="#Server.Coldfusion.SupportedLocales#" />

<cfloop list="#Server.Coldfusion.SupportedLocales#" index="locale" delimiters=",">
<cfset variables.oldlocale = SetLocale(locale) />
<cfoutput>

<p><strong>#locale#</strong></p>
<p>Locale-specific formats:</p>

<ul>
<li>#LSDateFormat(Now(), "mmm-dd-yyyy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now(), "mmmm d, yyyy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now(), "mm/dd/yyyy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now(), "d-mmm-yyyy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now(), "ddd, mmmm dd, yyyy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now(), "d/m/yy")# #LSTimeFormat(Now())#</li>
<li>#LSDateFormat(Now())# #LSTimeFormat(Now())#</li>
</ul>

<p>Standard Date/Time: #LSParseDateTime("#LSDateFormat(Now())# #LSTimeFormat(Now())#")#</p>

</cfoutput>
</cfloop>

However, all of the time returns 10:45!! Regardsless of what locale each is...is this correct? I'm really confused.

If someone could give me a primer on this for 2 minutes that would be great. I just want dates that sync up together regardless of where the user is in the world because my application is dependant on comparing these times.

Thanks,
Mikey.
592
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 02, 2008 Apr 02, 2008
The #now()# function gets its time from the ColdFusion server, not the "users computer". Database local time functions, such as sysdate, now() and getdate(), get their times from the database server, etc.

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2008 Apr 02, 2008
Just to add, the Now() function does get the time from the coldfusion server. It cannot get the time from the users computer because the script is executed on the server and cannot and is all server side code.... Javascript would access the users computer time/date...

I am not sure what you situation is, but I have had similar issues that were a result of the server my site was hosted on (third party hosting) was not in the same timezone as myself therefore making the times all off by 1 hour. If you have your own server this is probably not the case, but I just thought I would add this just incase.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2008 Apr 02, 2008
Hi,

Thanks for the reply...that explains a bit.

So, if the time I am getting returned is 10:00 AM from the server, and the time in the UK which is GMT time is 01:00 PM...how can I convert the server time to use and return GMT time?

I don't have access to the server myself, I'm on a shared hosting environment (hostMySite)

Thanks,
Mikey.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2008 Apr 02, 2008
LATEST
Kapitaine wrote:
> <h3>LSParseDateTime Example - returns a locale-specific date/time object</h3>
> <!--- loop through a list of locales and show date values for Now()--->

locales have nothing to do w/timezones (tz). countries are the closest "unit" to
a tz. you might try the info from this CFC:

http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=8B31D607-20ED-7DEE-2AFB38EF88DA...

> However, all of the time returns 10:45!! Regardsless of what locale each
> is...is this correct? I'm really confused.

yes that's correct. if you drive an italian car then swap to a german one, does
the time change because it's made in germany?

> If someone could give me a primer on this for 2 minutes that would be great. I
> just want dates that sync up together regardless of where the user is in the
> world because my application is dependant on comparing these times.

you have to get the user's tz via some mechanism client side, you can try js BUT
the ids it returns don't match w/many java tz ids. you'll also have to be aware
that tz differences between server & client (one w/DST, one w/out DST) will mess
you up.

maybe start reading here:

http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=77223B6A-20ED-7DEE-2AB7FBB1F37A...

might be a good idea to use epoch offsets instead of raw datetimes.

this CFC should help once you get the users tz:

http://www.sustainablegis.com/projects/tz/testTZCFC.cfm
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources