I'm feeding an android application with a xml having a datetime attribute. Problem here is, the application is accepting datetime by 13 digit number like 1347712845061. I'm not able to find an options to do this type of conversion in c#.
Do anyone have any suggestion?
Assuming that sample value was meant to be Sat, 15 Sep 2012 12:40:45 UTC, it just means "number of milliseconds since the Unix epoch". (That's the information within a java.util.Date
.) So you can write:
private static readonly DateTime UnixEpoch =
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static DateTime FromJavaDate(long millisSinceEpoch)
{
return UnixEpoch.AddMilliseconds(millisSinceEpoch);
}
(You could use a DateTimeOffset
too, which would always have an offset of 0.)
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.