Voprosec Voprosec
Voprosec Voprosec

Reputation: 147

Convert date (c#)

Good day! Faced with the problem. Need to convert the date. In the database it is stored in the format:

1332622254
1332622368
1332622467
1332622551

I am with this format never encountered. What is this format, I do not know. Help to format it in vfeueshu. Thanks in advance.

Upvotes: 0

Views: 97

Answers (2)

Hans Kesting
Hans Kesting

Reputation: 39255

It's a time in seconds since midnight 1-1-1970:

var epoch = new DateTime(1970,1,1);
var ts = TimeSpan.FromSeconds(1332622254);
var date = epoch.Add(ts);

date is then 24-3-2012 20:50:54

EDIT
Or simpler, as MarcinJuraszek rightly stated:

var epoch = new DateTime(1970,1,1);
var date = epoch.AddSeconds(1332622254);

Note that this might be a date/time in UTC, so maybe you will have to adjust for your timezone.

Upvotes: 1

Daniil
Daniil

Reputation: 413

It's TimeSpan

TimeSpan a = new TimeSpan(1332622254);

Upvotes: 0

Related Questions