Solved

coldusion time of location other than server

Posted on 2011-03-01
5
860 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 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