[英]Format from ticks to date
I am needing to transfer some logs which were timestamped in ticks to an XML document. 我需要将一些带有时间戳的日志传输到XML文档中。 I would prefer the timestamps to be more Specific such as "July 14, 2009 10:18:04 pm"
我希望时间戳更具体,例如“2009年7月14日10:18:04 pm”
I was planning to using something along the line of: 我计划使用以下内容:
DateTime logDate = DateTime.Parse(logText);
logDate.ToString("MMM dd yyyy hh:mm:ss tt");
I figured this would be OK as DateTime.Now.Ticks is how you can get ticks. 我认为这可以,因为DateTime.Now.Ticks是你如何得到滴答。 It is however returning that it is not a proper DateTime format.
然而,它返回它不是一个正确的DateTime格式。 during setting logDate.
在设置logDate期间。
I am sure there is a simple solution but I just can't come across it. 我确信有一个简单的解决方案,但我无法遇到它。
如果logText
是一个字符串,您可以将其转换为long(Int64)并使用此构造函数 :
DateTime date = new DateTime(long.Parse(logText));
假设'logText'是刻度线,请尝试:
DateTime logDate = new DateTime(logText);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.