【问题标题】:reverse this function反转这个函数
【发布时间】:2010-05-30 04:05:43
【问题描述】:

我的代码采用 csharp 日期时间并将其转换为 long 以在“flot”图中绘制。这是代码

    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);
    }

我现在需要一个相反的函数,在该函数中我获取这个长值并取回 csharp 日期时间对象。知道上面的方法是否可以颠倒吗?

【问题讨论】:

    标签: c# javascript datetime


    【解决方案1】:
    DateTime date = new DateTime(1970, 1, 1).Add(new TimeSpan(yourLong * 10000));
    

    【讨论】:

      【解决方案2】:

      你不就是在找这个吗?

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

      【讨论】:

        【解决方案3】:

        可以是:

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

        【讨论】:

          猜你喜欢
          • 2018-06-25
          • 2013-09-04
          • 2015-04-23
          • 1970-01-01
          • 2020-08-16
          • 2022-10-05
          • 2019-05-12
          • 2018-04-20
          • 2021-07-27
          相关资源
          最近更新 更多