DateTime.Now与DateTime.UtcNow [英] DateTime.Now vs. DateTime.UtcNow

查看:124
本文介绍了DateTime.Now与DateTime.UtcNow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道究竟是如何的两个属性的工作原理。我知道,第二个是普遍的,基本不处理时区,但有人可以详细解释他们是如何工作的,哪些人应该在什么情况下使用?

I've been wondering what exactly are the principles of how the two properties work. I know the second one is universal and basically doesn't deal with time zones, but can someone explain in detail how they work and which one should be used in what scenario?

推荐答案

DateTime.UtcNow 告诉你的日期和时间,因为它会在协调世界时,也被称为格林威治标准时间的时区 - 基本上就像这将是,如果你在英国伦敦,而不是夏天。 DateTime.Now 的给出的日期和时间,因为它似乎有人在你当前的语言环境。

DateTime.UtcNow tells you the date and time as it would be in Coordinated Universal Time, which is also called the Greenwich Mean Time time zone - basically like it would be if you were in London England, but not during the summer. DateTime.Now gives the date and time as it would appear to someone in your current locale.

我推荐使用 DateTime.Now 每当你显示一个日期到一个人 - 这样他们满意,他们看到的价值 - 它的东西他们可以很容易地比较他们自己的钟表看到的。使用 DateTime.UtcNow 当你想存储日期或将其用于以后的计算方法,方式(在客户机 - 服务器模式)的计算没有在不同的客户端变得混乱时区从您的服务器或从对方。

I'd recommend using DateTime.Now whenever you're displaying a date to a human being - that way they're comfortable with the value they see - it's something that they can easily compare to what they see on their watch or clock. Use DateTime.UtcNow when you want to store dates or use them for later calculations that way (in a client-server model) your calculations don't become confused by clients in different time zones from your server or from each other.

这篇关于DateTime.Now与DateTime.UtcNow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆