c# - Convert format of datetime to another format of datetime -


my code parses raw data , turns datetime string format such below

string birthday  = "20" + year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + second; 

so birthday string , converted datetime format such below

datetime bdaylater= convert.todatetime(birthday); 

the result became 1 below

7/8/2015 5:02:05 

in wanted convert 1 below

2015/07/08 05:02:05.000 

how can achieve such result.

thanks.

you should format date variable before printing same

string birthday  = "2015" + "-" + "07" + "-" + "08" + " " + "05" + ":" + "02" + ":" + "05"; datetime bdaylater= convert.todatetime(birthday); console.writeline(bdaylater.tostring("yyyy/mm/dd hh:mm:ss.mmm")); 

this give o/p 2015/07/08 05:02:05.02

fiddle example

if want 000 in millisecond string "yyyy/mm/dd hh:mm:ss.000"


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -