c# - How to change "CurrentThread.CurrentCulture.DateTimeFormat" -


i inherited code following:

system.datetime datetimeout; if(datetime.tryparse("18/06/2015", out datetimeout)) {   console.writeline("good job!"); } 

"good job!" never printed out. msdn found datetime.tryparse uses datetime format system.globalization.datetimeformatinfo.currentinfo in turn thread.currentthread.currentculture.datetimeformat. , in system "mm/dd/yyyy" - that's why "18/06/2015" cannot parsed.

then went control panel , changed datetime format "dd/mm/yyyy" , restarted pc. when run program again, thread.currentthread.currentculture.datetimeformat still "mm/dd/yyyy"....i wondering controls setting , can change it?

specify culture:

system.datetime datetimeout; var culture = cultureinfo.createspecificculture("en-gb"); var styles = datetimestyles.none; if (datetime.tryparse("18/06/2015", culture, styles, out datetimeout)) {   console.writeline("good job!"); } 

good job sent console here.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -