Syed Mhamudul Hasan
Syed Mhamudul Hasan

Reputation: 1349

Unknown date format in Api

I am working with HighStock chart link

It use data from a api apilink

First parameter is date like

[
/* Sep 2009 */
[1252368000000,24.70],
..
]

What is this date format ? How to get this format is C#?

Upvotes: 1

Views: 108

Answers (2)

Rana Hamid
Rana Hamid

Reputation: 53

 /// <summary>
    /// Dates  represented as Unix timestamp 
    /// with slight modification: it defined as the number
    /// of seconds that have elapsed since 00:00:00, Thursday, 1 January 1970.
    /// To convert it to .NET DateTime use following extension
    /// </summary>
    /// <param name="_time">DateTime</param>
    /// <returns>Return as DateTime of uint time
    /// </returns>
    public DateTime ToDateTime( uint _time)
    {
        return new DateTime(1970, 1, 1).AddSeconds(_time);
    }

    /// <summary>
    /// Dates  represented as Unix timestamp 
    /// with slight modification: it defined as the number
    /// of seconds that have elapsed since 00:00:00 Thursday, 1 January 1970.
    /// To convert .NET DateTime to Unix time use following extension
    /// </summary>
    /// <param name="_time">DateTime</param>
    /// <returns>
    /// Return as uint time of DateTime
    /// </returns>

    public uint ToUnixTime(DateTime _time)
    {
        return (uint)_time.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
    }

Upvotes: 3

grovesNL
grovesNL

Reputation: 6075

This appears to be a JavaScript date value, which is provided in terms of milliseconds elapsed since the epoch of January 1st, 1970.

You can convert it to a DateTime several ways in C#.

For example (from the link above), you can add the ticks elapsed since the JavaScript epoch. To convert from milliseconds to ticks, multiply by 10,000. Therefore you could write the following:

new DateTime(1970, 1, 1).AddTicks(1252368000000 * 10000);

Upvotes: 3

Related Questions