Solved

coldusion time of location other than server

Posted on 2011-03-01
5
867 Views
Last Modified: 2012-05-11
I host a website in Perth, Australia.

Website is for a group in Melbourne, Australia.

Perth is 3 hours behind melbourne, so when writing a record to the database, the now() function writes the time of the server in perth.  But I need to write the time the event occured in melbourne.

I could just use DateAdd to subtract 3 hours from now(), but then when Daylight Savings finishes in Melbourne (Perth doesn't have Daylight savings), I need to subtract 4 hours from now().  The problem is, I can't work out how the server in Perth is not know Whether or not it is daylight savings time in melbourne.

I may be going about this wrong, but if anyone has any suggestions on how a server in one timezone can best know the current time in another timezone (factoring in daylight savings), I would love to hear it.

Many Thanks in advance.

0
Comment
Question by:Jay1607
5 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35014735
Hi,

Can we use client side scripting? Javascript

If I'm not mistaken, you wanted client side time.right?


- Bhavesh
<input type="Text" name="text1" id="text1" value="">

<script>
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
text1.value = hours + ":" + minutes + " ";
if(hours > 11){
text1.value += "PM";
} else {
text1.value += "AM";
}
</script>

Open in new window

0
 

Author Comment

by:Jay1607
ID: 35014759
Not really...

I need to be able to know, on the server, what time it is in another time zone...



0
 
LVL 11

Accepted Solution

by:
Brijesh Chauhan earned 250 total points
ID: 35014781
Download the timezone.cfc from the below link

https://github.com/rip747/TimeZone-CFC

this will give you the time of the zone that you are looking for...
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 250 total points
ID: 35022526
Whether or not it is daylight savings time in melbourne

The cfc and similar methods boil down to using TimeZone objects.  Pass in melbourne's timezone and a date object and inDaylightTime() tells you whether it's in DST or not.  Notice it returns "yes" for today March 7, 2011. But "no" for a date like April 3rd when I believe DST ends.

CF8 example
<!--- test when DST changes in Melbourne
<cfset serverDate = createDateTime(2011, 4, 3, 3, 0, 0)> --->
<cfset serverDate = now()>
<cfset zone  = createObject("java", "java.util.TimeZone").getTimeZone("Australia/Melbourne")>
<cfset isDST = zone.inDaylightTime(testDate)>
<cfset offset = (isDST ? 3 : 4 )>
<cfset melbourneDate = dateAdd("h", offset, testDate )>
<cfoutput>
	isDST? = #isDST#<br />
	serverDate = #serverDate# <br />
	melbourneDate = #melbourneDate# <br />
</cfoutput>

Open in new window


when writing a record to the database, the now() function writes the time of the server

You could also store the dates in UTC so you could convert them to any timezone.  But that's up to you.

ie <cfset eventDate = DateConvert("local2Utc", now())>
0
 

Author Closing Comment

by:Jay1607
ID: 35023325
Lovely.  Thank you guys!!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now