Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display GMT date and time NOT the local time in a label

Tags:

c#

datetime

I currently use:

lable1.Text = DateTime.Now.ToShortDateString();

to display the short date time in my label1.

Because the code above shows the date from windows machine (if you change the date in windows clock settings date in program is also changed) this doesn't help me any more. I need to display the GMT date and time in label1 (GMT+0 date) and label2 (GMT+0 clock), so that the date and time will be displayed independent from windows machine clock settings.

I don't have any clue how to make this. Remember that I have a 24 hour system not 12.

like image 681
Matej Merc Avatar asked Jan 11 '23 22:01

Matej Merc


1 Answers

Use UtcNow property like this:

label1.Text = DateTime.UtcNow.ToShortDateString();
like image 122
Den Pakizh Avatar answered Feb 02 '23 07:02

Den Pakizh