CodeDada
CodeDada

Reputation: 435

how to convert datetime value to zulu time zone format in c#?

the current value i have when fetched from database is

2018-02-13T12:36:00 ;

//but i need it to be convert like below (where z and the end denotes zulu timezone)

2018-02-13T12:36:00Z ; 

Note :i am storing the value in a datetime variable and i dont want this in a string format.i tried converting it to string and append Z to it but it
changes the format like this which is not expected result.Any help is appreciated

2/13/2018 12:36: PMZ

Upvotes: 1

Views: 9912

Answers (2)

Andiih
Andiih

Reputation: 12423

Building on @CodeDada answer, try

.ToUniversalTime().ToString("u");

This first converts to Universal (zulu) time, then formats the output correctly including the Z suffix

Upvotes: 0

CodeDada
CodeDada

Reputation: 435

The Answer is

.ToUniversalTime() 

it converts the date time to Zulu time zone format as it is a part of UTC Time Zone(Zulu time zone is -UTC +0 )

The example mentioned in This MSDN article did not mention about 'Z'(Zulu time zone indication) but this method does convert to Zulu time zone.

Upvotes: 2

Related Questions