asp.net - DateTime.TryParseExact does not process long format strings -


i have try , parse out date time string causing trouble.

most of time string follows

'sat aug 10 08:01:37 2013'         ^ note 1 space 

my original date format tryparseexact 'ddd mmm d hh:mm:ss yyyy'

however, on single digit days, digit in ten's place not deleted, instead replaced space (see below)

'wed aug  7 08:01:37 2013'         ^^ note 2 spaces  

my first idea remove spaces achieve format string:

'dddmmmdhh:mm:ssyyyy' 

but datetime.tryparseexact fails , never accepts newly formatted (spaceless) format string. why?

because tryparseexact, spacing of date important.

it's bit hacky, if no better solution presented, tryparseexact using 'ddd mmm d hh:mm:ss yyyy' , if fails, tryparseexact using 'ddd mmm d hh:mm:ss yyyy' (with 2 spaces)


edit

i think found smarter way, pass datetimestyles.allowinnerwhite tryparseexact method.

according docs:

extra white-space characters in middle of string must ignored during parsing, except if occur in datetimeformatinfo format patterns.

not sure means "except if occur in datetimeformatinfo format patterns." worth try.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -