PHP有个函数,可以将日期转换成如下格式:
<startTime>1286035200</startTime> 
  <endTime>1286640000</endTime> 
请问:如何在asp.net中将上面的时间格式,转换成2009-10-11 19:33:33这种格式呢?

解决方案 »

  1.   

    dateTimdObj.ToString("yyyy-MM-dd HH:mm:ss")
      

  2.   

    日期的毫秒数是从1970-01-01 00:00:00开始算的
    DateTime dt = new DateTime(1970, 1, 1).AddSeconds(i);   
     
    public static double TotalMillisecondsFrom70(string sdt)
            {
                DateTime d1 = new DateTime();
                if (DateTime.TryParse(sdt, out d1))
                {
                    DateTime d2 = new DateTime(1970, 1, 1);
                    return d1.Subtract(d2).TotalMilliseconds;
                }
                return 0;
            }
      

  3.   

    日期转化样式是LS这样对的:yyyy-MM-dd HH:mm:ss
      

  4.   

    这是我做的 ASP.NET 接收团购接口 提供的基本上通用的时间转换 方法
      private string ConvertDateTime(string time)
            {
                try
                {
                    if (time.Length == 10)
                    {
                        DateTime t = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(Convert.ToInt32(time));
                        return t.ToString();
                    }
                    else
                    {
                        if (time.IndexOf("T") != -1)
                            time = time.Replace("T", " ");
                        if (time.IndexOf("+") != -1)
                            time = time.Substring(0, time.IndexOf("+"));
                        return time;
                    }
                }
                catch
                {
                    return Utils.GetDateTime();
                }        }
    DateTime t = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(Convert.ToInt32(time));
    这句 是你想要的
      

  5.   

    基本上 可以转换很多 团购网站提供API里的 时间格式了 
      

  6.   

    基本上 可以转换很多 团购网站提供API里的 时间格式了 
      

  7.   

    DateTime dt = DateTime.Now;
    dt.ToString("yyyy-MM-dd HH:mm:ss");
      

  8.   

    string str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
      

  9.   

    string str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");