mysql - Convert string to DateTime without changing the original string 's format c# -


i reading date-time mysql database table kept on server current sever date-time using query "select now()".i date-time.

var tmpstring = datetime.parse(reader[0].tostring()).tostring("yyyy-mm-dd hh:mm:ss tt"); datetime result = convert.todatetime(tmpstring); 

reader[0] contains server's current date time. tmpstring has value "2017-04-06 03:10:20 pm"

result contains date-time in following format : 06-apr-17 3:10:20 pm (my machine's date-time format)

but want date-time per servers date-time format ("yyyy-mm-dd hh:mm:ss tt")

i've tried using

datetime result = datetime.parseexact(tmpstring, "yyyy-mm-dd hh:mm:ss tt", cultureinfo.invariantculture); 

which returns 06-apr-17 3:16:11 pm.

it may full

        system.globalization.cultureinfo customculture = new system.globalization.cultureinfo("en-us", true);          customculture.datetimeformat.shortdatepattern = "yyyy-mm-dd h:mm tt";          system.threading.thread.currentthread.currentculture = customculture;         system.threading.thread.currentthread.currentuiculture = customculture;          datetime newdate = system.convert.todatetime(datetime.now.tostring("yyyy-mm-dd h:mm tt")); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -