Question: How to transform Different timezone

Question

How to transform Different timezone

Answers 0
Added at 2017-11-08 15:11
Tags
Question

I'm using

TimeZone-CFC

How do you transform

  • PT to PST or PDT
  • MT to MST or MDT
  • CT to CST or CDT
  • ET to EST or EDT

I've checked the list of TimeZone but PT,MT,CT and ET are not in the timezone list.

I was thinking I can map the PT,MT,CT,ET like:

<!--- use Pacific time as sample --->
<cfset varTimeZone = "PT">

<cfif varTimeZone is "PT">
    <cfset useTZ = "US/Pacific">
<cfelseif varTimeZone is "ET">  
    <cfset useTZ = "US/Eastern">
<cfelseif varTimeZone is "CT">  
    <cfset useTZ = "US/Central">
<cfelseif varTimeZone is "MT">
    <cfset useTZ = "US/Mountain">       
</cfif>


<cfdump var="#application.tz.castFromUTC(utcDate,useTZ)#">

If I have a date like "2017-10-25 03:41:29.000" which is in UTC. I will need to display it in PST.

Another one to consider is the server uses "America/New_York" timezone. To get server timezone:

<!--- server timezone --->
<cfset tz = CreateObject("java", "java.util.TimeZone")>
<cfset tz = tz.getDefault()>
<cfoutput>TimeZone: #tz.getDisplayName()# (#tz.getID()#)</cfoutput>

If the server is in UTC it would have been easier.

Answers to

How to transform Different timezone

Source Show
◀ Wstecz