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
Post a Comment