如何在列表中转换Unix日期时间? [英] How to convert Unix date time in list?

查看:78
本文介绍了如何在列表中转换Unix日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有产品清单



I have list of products

List<Products> prodlist=ctx.Products.ToList();







我有一个字段叫做RecordSubmitTime 这是Unix形式的10个数字数据,例如5412365478。



i希望将所有RecordSubmitTime转换为DateTime格式并存储为prodlist作为新列Rec_Date_Time我该怎么办呢。







先谢谢。




I have One field in it Called "RecordSubmitTime" which is in Unix form 10 number data for example "5412365478".

i want to convert all "RecordSubmitTime" into DateTime format and store into "prodlist" as new column "Rec_Date_Time" how can i do this.



Thanks In Advance.

推荐答案

这是如何:

http:// en。 wikipedia.org/wiki/Unix_time [ ^ ],

http:// stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa [ ^ ]。



-SA
This is how:
http://en.wikipedia.org/wiki/Unix_time[^],
http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa[^].

—SA


DateTime S_Date;
List<formated> dt=new List<formated>();
Formated f;


List<products> prodlist=ctx.Products.ToList();

foreach(var item in prodlist)
{

S_Date = new DateTime(1970,1,1,0,0,0,0, System.DateTimeKind.Utc); 
S_Date = S_Date.AddSeconds(Convert.ToDouble(item.RecordSubmitTime)).ToLocalTime();

//Storing the data into List<>

f=new Formated();
f.ProdName=item.ProdName;
f.Date=gdate;
dt.Add(f);

}


public class Formated
{
public string ProdName{get;set;}
public DateTime Date{get;set;}
}


这篇关于如何在列表中转换Unix日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆