简体   繁体   中英

Format from ticks to date

I am needing to transfer some logs which were timestamped in ticks to an XML document. I would prefer the timestamps to be more Specific such as "July 14, 2009 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. It is however returning that it is not a proper DateTime format. during setting 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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