[英]Convert datetime ticks(String.Format(“{0:D19}”, DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks) to datetime
I am storing Azure table storage rowkey in date time ticks format 我以日期时间刻度格式存储Azure表存储rowkey
String.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks);
and I want to convert back to date time. 我想转换回日期时间。
If you are doing: 如果你这样做:
string str = String.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks);
Then we have that 那我们就有了
// str = max - now
so then 那么
// now = max - str
so 所以
DateTime now = new DateTime(DateTime.MaxValue.Ticks - long.Parse(str), DateTimeKind.Utc);
Your code returns 2519440974768899656
on my timezone which is UTC +02:00 right now, you can parse this string to long
and can use in DateTime(long)
constructor. 您的代码在我的时区返回2519440974768899656
,现在是UTC +02:00,您可以将此字符串解析为long
并且可以在DateTime(long)
构造函数中使用。
var s = String.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks).Dump();
long l = long.Parse(s);
(new DateTime(l)).Dump();
Returns 返回
16.10.7984 15:31:16
But honestly, depending what you doing, I'm not quite sure this is the value you want. 但说实话,这取决于你在做什么,我不太确定这是你想要的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.