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?

1
  • 2
    Wrap the ternary expression in parenthesis. Commented Jan 17, 2022 at 12:52

1 Answer 1

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")}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.