0

I want to create a datetime string but add CET/CEST depending if it's daylight savings or not.

$"{DateTime.Now.ToString("MMMM dd, yyyy, hh:mm tt"} {TimeZoneInfo.Utc.IsDaylightSavingTime(message.RegistrationTime) ? "CEST" : "CET"}

so if IsDaylightSavingTime returns true, append "CEST" string, if not, just "CET".

Is there an easy/quick way to do this?

GeorgeR
  • 149
  • 9

1 Answers1

3

You can wrap the ternary operator in () brackets when using string interpolation. So the ternary operator in the string interpolation would become:

 {(TimeZoneInfo.Utc.IsDaylightSavingTime(message.RegistrationTime) ? "CEST" : "CET")}
haldo
  • 14,512
  • 5
  • 46
  • 52