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

convert time

New Here ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

i am using a cfschedule to match the time and date in my database table with the Now() function to send out the sms which works fine.

accept it matches the time and date with the server time and date not the time and date of the local area it was entered ie UK Australia etc


my server is in australia, say if a user in the UK selects a time of '08:00:00' from a list box, before inserting into my database can i convert that somehow to what my server time would be ?
TOPICS
Advanced techniques

Views

887

Translate

Translate

Report

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 ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

Checkout the LS date and time functions, they may help.

Votes

Translate

Translate

Report

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
New Here ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

ok yes i have tried that with the code below but it diplays the same time for each time zone

any ideas?

<cfloop LIST = "#Server.Coldfusion.SupportedLocales#"
index = "locale" delimiters = ",">
<cfset oldlocale = SetLocale(locale)>

<cfoutput><p><B><I>#locale#</I></B><br>
#LSTimeFormat(Now())#<br>
#LSTimeFormat(Now(), 'hh:mm:ss')#<br>
#LSTimeFormat(Now(), 'hh:mm:sst')#<br>
#LSTimeFormat(Now(), 'hh:mm:sstt')#<br>
#LSTimeFormat(Now(), 'HH:mm:ss')#<br>
<hr noshade>
</cfoutput>

</cfloop>

Votes

Translate

Translate

Report

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
Advocate ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

Unless you have some way to tie a user with a specific geographic area (such as a user profile, etc), I'm not sure coldfusion can tell what time zone a request is coming from. You could probably hack something together using the user's IP address, but a better solution might be to use JavaScript to set a hidden date field so that when the user submits the form you get the date associated with his/her machine.

Votes

Translate

Translate

Report

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
New Here ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

ok i have worked out i need to do this

<cfset localtime = '#form.SMS_Date# #form.SMS_Time#' + #info.utcTotalOffset#>

but i need to convert my forms date and time into a date-time format how can i do this

Votes

Translate

Translate

Report

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 ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> ok i have worked out i need to do this
>
> <cfset localtime = '#form.SMS_Date# #form.SMS_Time#' + #info.utcTotalOffset#>
>
> but i need to convert my forms date and time into a date-time format how can i
> do this

you also need to take DST into consideration for both the server & the client.

Votes

Translate

Translate

Report

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 ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

Among the functions you can use are:
createdate
createdatetime
createodbcdate
createodbcdatetime
dateformat

Votes

Translate

Translate

Report

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
New Here ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

ok thanks, just getting one problem

<cfset info = GetTimeZoneInfo()>
<CFSET yourDate = CreateDateTime (form.year, form.month, form.day, form.hour, form.minute, form.second)>
<cfset localtime = #yourDate# + #info.utcHourOffset#>

<cfoutput>
Server Time = #localtime#
</cfoutput>

but instead of showing the time it shows this number 35944.675

any ideas

Votes

Translate

Translate

Report

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 ,
Dec 12, 2006 Dec 12, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> ok thanks, just getting one problem
>
> <cfset info = GetTimeZoneInfo()>
> <CFSET yourDate = CreateDateTime (form.year, form.month, form.day, form.hour,
> form.minute, form.second)>
> <cfset localtime = #yourDate# + #info.utcHourOffset#>
>
> <cfoutput>
> Server Time = #localtime#
> </cfoutput>
>
> but instead of showing the time it shows this number 35944.675

that's decimal days since the start of cf epoch (13-dec-1899). you want dateAdd
method.

dateAdd("h",info.utcHourOffset,CreateDateTime (form.year, form.month,
form.day,form.hour,form.minute, form.second))

and again you're not accounting for DST differences.

Votes

Translate

Translate

Report

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
New Here ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

ok many thanks for that, i thought the GetTimeZoneInfo() get the local time of the users computer so would that not include DST?

if not how would i get DST?

Votes

Translate

Translate

Report

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 ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> ok many thanks for that, i thought the GetTimeZoneInfo() get the local time
> of the users computer so would that not include DST?

server side.

> if not how would i get DST?

simplest to ask them for their timezone (tz) or maybe give them the choice when
they schedule the task. if you know their country & can use the icu4j lib you
can get tz by country from it, well a set of tz anyway.

Votes

Translate

Translate

Report

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
New Here ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

ok thanks

so if i get the user to select from a list box the timezone how do i populate the list box to have a value of there tz?

Votes

Translate

Translate

Report

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 ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> so if i get the user to select from a list box the timezone how do i populate
> the list box to have a value of there tz?

http://www.sustainablegis.com/projects/tz/testTZCFC.cfm

Votes

Translate

Translate

Report

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
New Here ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

ok yes i see, just one more thing, i have in my table a column called datetime,

say a user was in the UK and selects 08:00:00 as a time and 13/12/2006 as the date from my list boxes, from the tz column in my table how can i convert the selected time and date in the the tz of the server before in insert it to my table

Votes

Translate

Translate

Report

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 ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> ok yes i see, just one more thing, i have in my table a column called datetime,
>
> say a user was in the UK and selects 08:00:00 as a time and 13/12/2006 as the
> date from my list boxes, from the tz column in my table how can i convert the
> selected time and date in the the tz of the server before in insert it to my
> table

if these are separate fields, build a datetime using createdate. "cast" that to
UTC based on their tz. cast that UTC datetime to server time. the CFC's method
will handle DST for you.

Votes

Translate

Translate

Report

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
New Here ,
Dec 13, 2006 Dec 13, 2006

Copy link to clipboard

Copied

LATEST
hi i dont understand what you mean by cast? are there any code examples on what i need to do

also how do i limit the values of the testTZCFC.cfm list box i only need a few time zones

Votes

Translate

Translate

Report

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
Documentation