简体   繁体   English

UTC DateTime返回原始日期时间

[英]UTC DateTime back to Original datetime

I have probably just stared at this too long... 我可能只是盯着这个太久了...

I have a third-party datepicker (ASP/MVC) and I stringify the array of selected dates and pass it to the controller. 我有一个第三方datepicker(ASP / MVC),我将选定日期的数组字符串化并将其传递给控制器​​。

example: 例:

  • My browser is US EST time zone. 我的浏览器是美国东部标准时间所在的时区。
  • I select 5/21/2013 我选择5/21/2013
  • when I stringify it I get ["2013-05-21T04:00:00Z"] (UTC) 当我将其字符串化时,会得到[“ 2013-05-21T04:00:00Z”](UTC)
  • I pass it back to the webserver that is in Us PST timezone 我将其传回美国PST时区的Web服务器
  • I want to get it back to 5/21/2013 12:00:00AM 我想回到5/21/2013 12:00:00 AM

I know that this is meant to be midnight since it is from a timeless datepicker. 我知道这是午夜,因为它来自永恒的日期选择器。

In c#, how do I convert this back to its original time? 在C#中,如何将其转换回原始时间? I am in PST but that should not matter. 我在PST,但这无关紧要。

Try 尝试

string date = "2013-05-21T04:00:00Z" ;
DateTime dt = Datetime.parse(date);
dt = dt.Date;

You will get the date component only, with the time component as midnight. 您将仅获得日期部分,而时间部分为午夜。 I hope this satisfies your requirement. 我希望这能满足您的要求。

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

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