某个程序使用php中的time()数据向mysql写入日期(如:1125114878 as int)
而后我将mysql库转换成sqlserver,发现日期字段类型为decimal,内容为:1125114878进过咨询,在php中可用如下方法还原:
date('Y-m-d h:i:s',time());那么在c#,或者在t-sql中是否有同样的方法可以对数据库中的日期内容进行还原!?
而后我将mysql库转换成sqlserver,发现日期字段类型为decimal,内容为:1125114878进过咨询,在php中可用如下方法还原:
date('Y-m-d h:i:s',time());那么在c#,或者在t-sql中是否有同样的方法可以对数据库中的日期内容进行还原!?
DateTime t;
t=(DateTime)str;
this.Label1.Text=t.ToString();编译提示无法将decimal转换为datetime格式!
decimal str=1124899200;
DateTime dt = new DateTime(str);
检验一下对不对
DateTime t=new DateTime(str);
this.Label1.Text=t.ToString();返回时间不对,可能是unix的时间戳格式和windows的时间戳格式不同吧!?
DateTime.FromFileTimeUtc()
DateTime.FromOADate()
DateTime.FromFileTime()
DateTime.FromFileTimeUtc()如果都不对,就得研究一下原来的时间格式是什么了:)
long str=1125086636;
DateTime t=DateTime.FromFileTimeUtc(str);
MSG.Text=t.ToString();显示结果为:1601-1-1 0:01:52,而实际的应为:2005-9-3 05:35 PM估计php的time()写入的是unix的时间戳吧!?不解,望高手们帮帮忙!
DateTime dt = new DateTime(1970,1,1);
dt = dt.AddSeconds(str);
Console.WriteLine(dt.ToString());你上面的实际时间应该是错误的,正确的是:2005-8-26 20:03:56
long str=long.Parse(time.Text.Trim());
DateTime dt = new DateTime(1969,12,31,20,0,0);
dt = dt.AddSeconds(str);
this.Label1.Text=dt.ToString();