1

I am given a date like these:

1555473600 1555560000

Is there a term for this type of date and how do I convert it to something like 12/28/2018 1:00 pm for example?

Thanks!

ErocM
  • 4,505
  • 24
  • 94
  • 161
  • 2
    Looks like an Unix timestamps. Check this [question](https://stackoverflow.com/q/249760/4685428) for more details – Aleks Andreev Apr 17 '19 at 20:42
  • Are you referring to Epoch maybe? Basically its the number of milliseconds from a specified `DateTime` like `1970-1-1`. If that is not it you will have to provide some more context like the origin of this data. – Igor Apr 17 '19 at 20:42
  • 1
    @AleksAndreev You are right, it is a Unix timestamp. I just reviewed the documentation. – ErocM Apr 17 '19 at 20:45
  • 1
    @Igor Thank you, I believe you are right. Where does the 1970-1-1 come from? Is that standard? – ErocM Apr 17 '19 at 20:46
  • 1
    @ErocM yes this is standard. Read more about [unix time](https://en.wikipedia.org/wiki/Unix_time) on wiki – Aleks Andreev Apr 17 '19 at 20:49
  • 1
    @Igor - https://codeofmatt.com/please-dont-call-it-epoch-time/ – Matt Johnson-Pint Apr 18 '19 at 00:01

2 Answers2

4

DateTimeOffset provides methods to convert to/from values based on the Unix epoch (1st January 1970, midnight UTC).

var dateTime1 = DateTimeOffset.FromUnixTimeSeconds(1555473600);
var dateTime2 = DateTimeOffset.FromUnixTimeMillieconds(1555560000);
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Neil
  • 11,059
  • 3
  • 31
  • 56
3

This looks to be a serial time, formatted in unix time. It is defined as the number of seconds since the unix epoch (January 1, 1970 midnight UTC).

Here is a hypothetical function for converting a unix time to human readable string.

private string epoch2string(int epoch) {
   return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch).ToShortDateString();
}

Now that you know what format that serial date is in, you can search the many posts discussing converting to/from unix time. Here is a useful link discussing unix time:

epoch converter

osprey
  • 708
  • 5
  • 15