I am creating an app for thailand using Xamarin form. There I need to fetch the current date time of thailand. As I am developing the app from India, my api calls (which are dependent on Datetime) are getting failed. I am trying to get the current datetime of Thailand. I have tried using Culture info but it is returning me the date in Buddhist calendar and time is not correct. My requirement is to get the time in following format. 20190602 15:50:51
-
Check out [this](https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones) Microsoft documentation page – MindSwipe Jun 03 '19 at 09:02
-
Dates have *no format*. They are binary values. The `DateTime` type is 100% unsuitable if you want to deal with timezones though. Its values are either UTC or Local, where `Local` means `whatever the machine's locale was when DateTime.Now was called` – Panagiotis Kanavos Jun 03 '19 at 09:03
-
Even using DateTime.UtcNow and performing the correct conversion means you get a value that you have no idea what timezone it points to. – Panagiotis Kanavos Jun 03 '19 at 09:04
-
It's far better to use the [DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset?view=netframework-4.8) type which includes the timezone offset. This means you always know what this value refers to. You can format this value on the client, use [ToOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tooffset?view=netframework-4.8) to convert it to a different timezone – Panagiotis Kanavos Jun 03 '19 at 09:07
-
As per my requirement,I need to have the time as per the time zone in thailand. – Mili Jun 03 '19 at 09:11
-
Maybe you need to look at [Noda Time](https://nodatime.org/)? – Hans Kesting Jun 03 '19 at 09:12
-
I want something like this:DateTime eastern = TimeZoneInfo.ConvertTimeBySystemTimeZoneId( DateTime.Now, "Indochina Time"); – Mili Jun 03 '19 at 09:16
-
Possible duplicate of [TimeZoneInfo.FindSystemTimeZoneById() throws exception in a Unity application](https://stackoverflow.com/questions/35043022/timezoneinfo-findsystemtimezonebyid-throws-exception-in-a-unity-application) – nilsK Jun 03 '19 at 11:02
3 Answers
var info = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
DateTimeOffset localTime = TimeZoneInfo.ConvertTime(localServerTime, info);
Then format however you need

- 922,412
- 146
- 1,693
- 2,536

- 2,127
- 16
- 33
There are two different time zone standards (well, not really standards, but de facto implementations):
The Microsoft Windows time zone data. The identifier for Thailand is
"SE Asia Standard Time"
.The IANA time zone database. The identifier for Thailand is
"Asia/Bangkok"
.
The TimeZoneInfo
object uses time zones defined by the operating system it is running on, hence the method name TimeZoneInfo.Find
System
TimeZoneById
. Since you're running on Android, not Windows, your OS likely uses the IANA IDs thus:
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Asia/Bangkok");
DateTime nowInThailand = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
Lastly, if you need to write your code such that it works cross-platform, then consider using my TimeZoneConverter library.
TimeZoneInfo tz = TimeZoneConverter.TZConvert.GetTimeTimeZoneInfo("Asia/Bangkok");
DateTime nowInThailand = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);

- 230,703
- 74
- 448
- 575
According to this and this Microsoft documentation Articles it should work
var now = DateTime.UtcNow;
try
{
var thaiZone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
var thaiTime = TimeZoneInfo.ConvertTimeFromUtc(now, thaiZone);
Console.WriteLine("The date and time in SE Asia Standard Time is {0} {1}", thaiTime, thaiZone.IsDaylightSavingTime(thaiTime) ? thaiZone.DaylightName : thaiZone.StandardName);
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine("The registry does not define the SE Asia Standard Time zone.");
}
catch (InvalidTimeZoneException)
{
Console.WriteLine("Registry data on the SE Asia Standard Time zone has been corrupted.");
}
Where thaiTime
is the current time in Thailand (SE Asia Standard Time)

- 7,193
- 24
- 47
-
Tried this. But getting TimeZoneNotFoundException in Android.Can you please help? – Mili Jun 03 '19 at 09:31