简体   繁体   English

在MVC应用程序中使用日期

[英]Using Dates in an MVC application

I have coded a MVC 5 internet application and have a question in regards to international dates. 我已经编写了MVC 5互联网应用程序的代码,并且对国际日期有疑问。

I am wishing to add a create date field to each of my objects when my objects are saved into a SQL database. 当我将对象保存到SQL数据库中时,我希望为每个对象添加一个创建日期字段。 As this application will be used internationally, what format should I use for the dates and do I need to use a specific UTC? 由于此应用程序将在国际范围内使用,因此日期应使用哪种格式,我是否需要使用特定的UTC?

Thanks in advance 提前致谢

The most common .NET type is DateTime. 最常见的.NET类型是DateTime。 A DateTime stores a date and optionally a time. DateTime存储日期和时间(可选)。 It has a Kind property which determines if the value is one of three: local, UTC, or unspecified. 它具有Kind属性,该属性确定值是以下三个之一:本地,UTC或未指定。 Another type is called DateTimeOffset. 另一种类型称为DateTimeOffset。 A DateTimeOffset stores a date and time relative to UTC. DateTimeOffset存储相对于UTC的日期和时间。 Additionally, it stores an offset from UTC as TimeSpan. 此外,它将与UTC的偏移量存储为TimeSpan。

Console.WriteLine (DateTime.Now); Console.WriteLine(DateTime.Now); // 1/28/2014 2:53:50 PM // 2014/1/28下午2:53:50

Console.WriteLine (DateTimeOffset.Now); Console.WriteLine(DateTimeOffset.Now); // 1/28/2014 2:53:50 PM -08:00 // 2014年1月28日2:53:50 PM -08:00

More Information : http://afana.me/post/aspnet-mvc-internationalization-date-time.aspx 详细信息: http : //afana.me/post/aspnet-mvc-internationalization-date-time.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM