Solved

coldusion time of location other than server

Posted on 2011-03-01
5
871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

735 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