0

I'm writing a C# Windows service that opens a text file that has a date and time column. Both of these are in CEST time in Germany. I need to know what these times are in EST. I don't know how to factor in the daylight savings time on both sides as well. Can someone please guide me with this? I have no idea how.

lsRetrievedDateTime = cellvalues[10] + " " + cellvalues[11];
ldRetrievedDateTimeCEST = DateTime.ParseExact(MyDateString, "M/dd/yyyy H:mm:ss", null);

//  ldRetrievedDateTimeCEST is actually Germany time and we need to convert it to EST.
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Andy
  • 383
  • 1
  • 6
  • 23
  • 3
    [Took me 2 seconds to google](https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones) – Daxtron2 Apr 24 '18 at 17:49
  • 1
    Be aware, `DateTime` itself doesn't keep time zone information. If you _really_ wanna deal with time zones, I suggest you to use [NodaTime](https://nodatime.org/) instead. – Soner Gönül Apr 24 '18 at 17:51
  • @TJWolschon, this includes DST adjustments as well? How do I start with CEST and not UTC to convert to EST? – Andy Apr 24 '18 at 18:01

1 Answers1

0

You can use TimeZoneInfo and DateTimeOffset

lsRetrievedDateTime = cellvalues[10] + " " + cellvalues[11];
ldRetrievedDateTimeCEST = DateTime.ParseExact(MyDateString, "M/dd/yyyy H:mm:ss", null)    
//Create a TimeZoneInfo Object and set TimeZone
var info = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
//Create DateTimeOffSet object with TimeZoneInfo and DateTime as parameters.

DateTimeOffset est_time = TimeZoneInfo.ConvertTime(ldRetrievedDateTimeCEST , info);

//Now you can use est_time

MessageBox.Show(est_time.ToString()); //will return EST time.

For diferent TimeZones you can check this question

Good Luck.

Juan Salvador Portugal
  • 1,233
  • 4
  • 20
  • 38