?
Solved

coldusion time of location other than server

Posted on 2011-03-01
5
Medium Priority
?
881 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 1000 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 1000 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
What You Need to Know when Searching for a Webhost Provider
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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