c# - Convert unix time to specific datetime format with culture info -


i try to convert string specific datetime format.

i have string:

1431075600 

and try convert by:

private static iformatprovider culture = new system.globalization.cultureinfo("en-gb"); model.deliverydate = datetime.parse(data.deliverydate, culture, system.globalization.datetimestyles.assumelocal); 

i got error message:

string not recognized valid datetime. 

finally want have datetime in format like

friday, 8 may 2015 hour: 09:00 

your string looks unix time elapsed seconds since 1 january 1970 00:00 utc.. that's why, can't directly parse datetime. need create unix time first , add value second.

that's why need add string second value like;

var dt = new datetime(1970, 1, 1, 0, 0, 0, 0, datetimekind.utc); dt = dt.addseconds(1431075600).tolocaltime(); 

and can format string after english-based culture line invariantculture;

console.writeline(dt.tostring("dddd, d mmm yyyy 'h'our: hh:mm",                               cultureinfo.invariantculture)); 

result be;

friday, 8 may 2015 hour: 09:00 

here demonstration.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -