开发者

reverse this function

i have code that takes a csharp datetime and conv开发者_开发技巧erts it into a long to plot in the "flot" graph. here is the code

    public static long GetJavascriptTimestamp(DateTime input)
    {
        TimeSpan span = new TimeSpan(DateTime.Parse("1/1/1970").Ticks);
        DateTime time = input.Subtract(span);
        return (long)(time.Ticks / 10000);
    }

I now need an opposite function where i take this long value and get the csharp datetime object back. any idea if the above method can be reversed ?


DateTime date = new DateTime(1970, 1, 1).Add(new TimeSpan(yourLong * 10000));


Aren't you just looking for this?

public static DateTime DateTimeFromJavascript(long millisecs)
{
    return new DateTime(1970, 1, 1).AddMilliseconds(millisecs);
}


Can be:

public static DateTime GetTimestampFromJS(long ts)
{
    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    return origin.AddSeconds(ts*1000);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜