I've been using Datetime.UtcNow
to get the date. However, this date is 6 hours ahead of my time (I'm in central time). Is there a more correct way for me to get the exact date in C#? Or if not, how would I change the existing date?
Asked
Active
Viewed 408 times
-6
-
You clearly made no effort to find the answer to this question before posting this here. A simple search would have answered this for you. – Dave Lucre Apr 17 '13 at 05:27
4 Answers
6
DateTime.Now
would give you current time for your time zone. DateTime.UtcNow
gives you current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

Habib
- 219,104
- 29
- 407
- 436
4
UTC time is Coordinated Universal Time, its a constant time that is the same no matter where you are. It's basically the same time in england, except it doesn't do daylight savings or anything like that.
to get your local time do DateTime.Now

Keith Nicholas
- 43,549
- 15
- 93
- 156
0
if you want it to be displayed in a label as well you could take a look at this code, it works for me. I used a timer to refresh the time everytime the timer ticks.
public partial class Form1 : Form
{
Timer timer = new Timer();
public Form1()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = (1000) * (1); // Timer will tick evert second
timer.Enabled = true; // Enable the timer
timer.Start(); // Start the timer
}
private void timer_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("HH:mm:ss");
}

Joey De Laat
- 136
- 1
- 15