Click here to Skip to main content
15,745,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have list of products

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



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.
Posted
Comments
Sergey Alexandrovich Kryukov 1-Jan-15 0:58am    
What have you tried so far?
—SA

C#
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;}
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900