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

cast UTC

New Here ,
Dec 15, 2006 Dec 15, 2006

Copy link to clipboard

Copied

Hi can someone help me i have 2 list boxes

1. Times = 08:00:00
2. Date = 12/12/2006

i need to convert this 2 list boxes to a datetime format then i need to convert the datetime to the server time, i have been told i need to cast it to UTC,

but not sure how to do this, any example code would be good

Many thanks

Keith
TOPICS
Advanced techniques

Views

2.1K

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

correct answers 1 Correct answer

LEGEND , Dec 17, 2006 Dec 17, 2006
Keith444 wrote:
> ok that worked but, but dont understand why it is English (Australian)

it represents a locale. starting w/cf 7.x cf locales are java locales.

> what does this represent, the users location or the servers location?

from what yo posted before, the user's locale NOT *just* their location but the
language, the ways they format dates, currency, etc.

> does this need to change for different users?

do you have users w/different locales?

> also i am now getting a date format er...

Votes

Translate

Translate
LEGEND ,
Dec 15, 2006 Dec 15, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> Hi can someone help me i have 2 list boxes
>
> 1. Times = 08:00:00
> 2. Date = 12/12/2006
>
> i need to convert this 2 list boxes to a datetime format then i need to
> convert the datetime to the server time, i have been told i need to cast it to
> UTC,
>
> but not sure how to do this, any example code would be good


<cfscript>
aTime="08:00:00";
aDate="12/12/2006";

// long way round
hour=listFirst(aTime,":");
minute=listGetAt(aTime,2,":");
second=listLast(aTime,":");
// you need to know your locale here, which came first, chicken or egg?
// assumming m/d/y, ie en_US
year=listLast(aDate,"/");
month=listFirst(aDate,"/");
day=listGetAt(aDate,2,"/");
aRealDate=createDateTime(year,month,day,hour,minute,second);
writeoutput("long way round:=#aRealDate#<br>");

//shortcut, again you still need to know locale
anotherDate=lsParseDateTime(aDate);
hours=hour+minute/60+second/360;
anotherRealDate=dateAdd("h",hours,anotherDate);
writeoutput("shortcut:=#anotherRealDate#");
</cfscript>

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

Copy link to clipboard

Copied

Hi Many thanks,

where you say "you need to know your locale here"

will this be the server locale or the locale time of the user?

if its the user i can get the user to select a time zone and have it stored in my database, if i do this what value would enter 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 15, 2006 Dec 15, 2006

Copy link to clipboard

Copied

Keith444 wrote:
> where you say "you need to know your locale here"
> will this be the server locale or the locale time of the user?

user.

> if its the user i can get the user to select a time zone and have it stored in
> my database, if i do this what value would enter to my table?

still need to know the date format you're showing to them.

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
Advisor ,
Dec 15, 2006 Dec 15, 2006

Copy link to clipboard

Copied

It doesn't have to be this complicated!
The CRITICAL thing, as Paul has hinted, is that you understand the date syntax the USER is using (mm/dd/yy, dd/mm/yy, etc.) and that you know and store the user's timezone offset.

See the attached.

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

Copy link to clipboard

Copied

MikerRoo wrote:
> It doesn't have to be this complicated!
> The CRITICAL thing, as Paul has hinted, is that you understand the date syntax
> the USER is using (mm/dd/yy, dd/mm/yy, etc.) and that you know and store the
> user's timezone offset.

once again, "no". you cannot simply store the offset. you need to manage the
complete timezone, otherwise DST differences will eventually bite 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 15, 2006 Dec 15, 2006

Copy link to clipboard

Copied

ok Paul,

the user has to list boxes with time format of hh:mm & date format dd/mm/yyyy

but what do i need to store in my table for the users time zone?

so say if user Craig has a time zone of Melbourne Australia, and i have a column in my table called timezone for each user what goes in there?

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
Community Expert ,
Dec 16, 2006 Dec 16, 2006

Copy link to clipboard

Copied

> say if user Craig has a time zone of Melbourne Australia, and i have a column in
> my table called timezone for each user what goes in there?

Remember that timezone is not just one property, but a set of properties, including offset, daylight savings, and so on.

Your "Melbourne Australia" amounts to the timezone ID called "Australia/Melbourne". So, I would convert the column's name to timezoneID instead.

You will get the list of timezone IDs by running

<cfset tz_id=createobject("java", "java.util.TimeZone").getAvailableIDs()>
<cfdump var="#tz_id#">

You will get the timezone information for the ID "Australia/Melbourne" by running

<cfset tz=createobject("java", "java.util.TimeZone").getTimeZone("Australia/Melbourne")>
<cfoutput>#tz#</cfoutput>


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

Copy link to clipboard

Copied

Keith444 wrote:
> but what do i need to store in my table for the users time zone?

their chosen tz id. i've used the latest icu4j lib to pull out tz IDs by
country, you can grab the CSV data from:

http://www.susteinableGIS.com/projects/tz/tzByCountry.zip

push that data into your database, when you offer tz choices to your users,
select the tz from that table by country. for instance this gets all the tz for
australia:

<cfquery datasource="lab" name="tz">
SELECT timezone
FROM timezones
WHERE countryISO3166='AU'
</cfquery>

then use the tz ID they choose in the timezone CFC i mentioned in one of your
other threads.

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

Copy link to clipboard

Copied

PaulH **AdobeCommunityExpert** wrote:
> http://www.susteinableGIS.com/projects/tz/tzByCountry.zip

i really should learn to spell, that should be:

http://www.sustainablegis.com/projects/tz/tzByCountry.zip

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
Advisor ,
Dec 16, 2006 Dec 16, 2006

Copy link to clipboard

Copied

quote:

Originally posted by: Newsgroup User
once again, "no". you cannot simply store the offset. you need to manage the
complete timezone, otherwise DST differences will eventually bite you.




Not really. The simple system is good enough 98% of the time. Maybe there is a small chance that it won't work for a few days for a few oddballs (odds are, non of the OP's customers). But, then again, those oddballs will be used to it (rather like "Tonee" always having to correct others on how her name is spelled) so no real damage there.

You've already given the OP your CFC system -- which is the smart and more correct way to go. He resisted.
Barring that, the simple system is better than most web sites and quite likely good enough.

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

Copy link to clipboard

Copied

MikerRoo wrote:
> Not really. The simple system is good enough 98% of the time. Maybe there

mike that's not good advice. if you're bothering w/timezone at all, then all DST
differences *are* important. coming from australia (i guess) i'd think you'd get
it more than most folks (DST changes to accommodate TV for the commonwealth
games, the recent WA "oops" tz changes, etc.).

at least i dug out the tz by country data 😉 maybe somebody will find that useful.

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
Advisor ,
Dec 16, 2006 Dec 16, 2006

Copy link to clipboard

Copied

You're right. I just thought that since OP wasn't seeming to grok the 100% solution (with free CFC's already built) that a "close enough" solution would get him further along the the desired path.

I withdraw the suggestion, above.

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

Copy link to clipboard

Copied

ok many thanlks paul nearly there i think?

if you look at url www.thesmsengine.com/times.cfm

is this ok for formats?

if so what will i need to put on my action page to convert this to server time

many thanks once again

Keith

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

Copy link to clipboard

Copied

Keith444 wrote:
> <td><select name="times">

terrible var name for timezones....


<cfscript>
// or wherever you put the timezone CFC
tz=createObject("component","cfc.i18n.timeZone");
// assuming this is user's locale, you need to manage these
setLocale("en_AU");
smsDate=lsParseDateTime(form.SMS_Date);
hours=listFirst(SMS_Time,":")+listGetAt(SMS_Time,2,":")/60+listLast(SMS_Time,":")/360;
smsDate=dateAdd("h",hours,smsDate);
// shortcut method i forgot about
serverDate=tz.castToServer(smsDate,form.times);
</cfscript>

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

Copy link to clipboard

Copied

ok yes i changed it from times to converttimes


what will be the varible the i can insert into my table as the server time?

will it be ServerDate

many thanks

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

Copy link to clipboard

Copied

Keith444 wrote:
> will it be ServerDate

yes.

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

Copy link to clipboard

Copied

"or wherever you put the timezone CFC"

Could not find the ColdFusion Component cfc.i18n.timeZone.

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

Copy link to clipboard

Copied

still dont understand, i have uploaded the timezone.cfc

what else do i need to do

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

Copy link to clipboard

Copied

Keith444 wrote:
> still dont understand, i have uploaded the timezone.cfc

where?

in the case of the example, "cfc.i18n.timeZone", "cfc" is a cf mapped dir
pointing at "c:\cfc\"

that cfc is in c:\cfc\i18n\timezone.cfc & referred to in cf programs as
cfc.i18n.timezone

you can put the cfc anywhere you want as long as you & cf know. if you don't
want to bother w/cf map dir, put the cfc in the same dir as the page calling it
& simple refer to it as "timezone":

tz=createObject("component","timeZone");

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

Copy link to clipboard

Copied

ok yes sorted it, now i just need to set my local

at the min it is "2en_AU"

does this need to be the server local time? if so i need this to be brisbane/australia i have tried it but dont work any ideas

or

does it need to be the users local? if so what value do i need from the timezone list box?

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
Enthusiast ,
Dec 16, 2006 Dec 16, 2006

Copy link to clipboard

Copied

the locale needs to be a java or cf standard locale ID such as "en_AU" not something you made up yourself.

not following the rest of your question.

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

Copy link to clipboard

Copied

ok so what is the cf standard for brisbane australia

just not sure where the form element coneverttime comes into the action page? thought i need to know what timezone the user is in?

<select name="converttimes">
<cfoutput query="tz">
<option value="#tz.timezone#">#tz.timezone#</option>
</cfoutput>
</select>

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
Community Expert ,
Dec 17, 2006 Dec 17, 2006

Copy link to clipboard

Copied

> ok so what is the cf standard for brisbane australia
Didn't you see what I wrote in answer to your similar question about Melbourne?

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

Copy link to clipboard

Copied

Keith444 wrote:
> ok so what is the cf standard for brisbane australia

you are confusing locale & timezone (tz). from what you've posted before you
need both. locale to handle the date string parsing. tz to handle, well, timezones.

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