Reputation: 127
I am creating a ColdFusion Application that needs to display the current time in in a number
of timezones and was wondering if anyone could tell me how to do this using java.util.TimeZone
?
What I have currently is assembled from different posts/articles :
<cfset timezoneClass = createObject( "java", "java.util.TimeZone" ) />
<cfset pragueZoneId = "Europe/Prague" />
<cfset pragueTimezone = timezoneClass.getTimeZone(javaCast( "string", pragueZoneId )) />
<cfset pragueCalendar = createObject( "java", "java.util.GregorianCalendar" ).init(pragueTimezone) />
I just don't know how to apply the above to get the current time for the timezone. Any help would be greatly appreciated. Thanks.
Upvotes: 4
Views: 370
Reputation: 7799
You need to create a Java SimpleDateFormat
object and configure it with the desired format you want to display the date/time. Then you can extract the Date
from the GregorianCalendar
using its getTime()
method and pass this value to SimpleDateFormat
to produce a String
that you can display.
A second variant is be to use method String.format()
using a format string and the result of getTime()
.
Alternatively, you can use method toString()
of the GregorianCalendar
object, but this is not recommended.
Upvotes: 4