- Home /
converting different time zones
I am having some issues converting timezones for some clocks. i have trolled the net for the answer but cant seem to get anything to work. what i am looking for is a simple solution to either covert time/date zones or a way to calculate them using the system time. here is what i have working so far to calculate local dates.
var MyFont: Font;
var test : int = 1;
var horizontal : int = 10;
var vertical : int = 10;
var tm : TextMesh = gameObject.GetComponent(TextMesh);
var timeString = System.DateTime.Now.ToString("hh:mm:ss");
var dateString = System.DateTime.Now.ToString("hh:mm MM/dd/yyyy");
var clockNameText = TextMesh;
function Update ()
{
tm.text= System.DateTime.Now.ToString("dd/MM");
}
Answer by Packetstorm · Dec 31, 2013 at 11:52 PM
hi all i will answer my own question...looked everywhere and just started mucking around with MonoDevelop until i found this answer with a little messing around. add the following changes and get the value of the float by dividing the time difference into 24 and your textmesh will show the accurate date. its not as elegant as i would like but its a working solution for now.
var timeDiff : float;
tm.text= System.DateTime.UtcNow.AddDays(timeDiff).ToString("dd/MM");
Answer by HappyMoo · Jan 01, 2014 at 12:11 AM
If you know the name of the Timezone, try this:
using System;
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime targetTime = TimeZoneInfo.ConvertTime(System.DateTime.Now, est);
But you should test this, as I don't know if this has a list of timezones on mobile or mac. This would also handle daylight savings time etc...
If you just want to add an offset, you can do:
float hoursOffset = -5f;
System.Datetime.UtcNow.AddHours(hoursOffset).ToLocalTime();
Be aware that timezones are a pain in the you know where.... http://www.youtube.com/watch?v=-5wpm-gesOY
float hoursOffset = -5f;
System.DateTime.UtcNow.AddHours(hoursOffset).ToLocalTime();
// quick note : System.DateTime is case sensitive.
Your answer
Follow this Question
Related Questions
Force mode and delta timing 1 Answer
How can I match up some code and an animation keyframe 0 Answers
When to use Time.deltaTime? 3 Answers