Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
128 views
Welcome To Ask or Share your Answers For Others

1 Answer

If logText is a string, you can convert it to long (Int64) and use this constructor:

DateTime date = new DateTime(long.Parse(logText));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...