Solved

coldusion time of location other than server

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link failure 16 90
Replace value 2 55
form isn't working is it missing a document 21 64
Domain hosting question about hiding URL 9 51
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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.
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

734 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