delphi - Converting a string to TDateTime based on an arbitrary format -



delphi - Converting a string to TDateTime based on an arbitrary format -

is there way in delphi 5 convert string tdatetime can specify actual format use?

i'm working on jobprocessor, accepts tasks various workstations. tasks have range of parameters, of dates, (unfortunately, , out of control) they're passed strings. since jobs can come different workstations, actual datetime format used format dates string might (and, of course, actual do) differ.

googling around, quick solutions found sneakily alter shortdateformat variable, , restore original value afterwards. since shortdateformat global variable, , i'm working in threaded environment way work synchronizing every access it, unacceptable (and undoable).

i re-create library code sysutils unit own methods, , tweak them work specified format instead of global variables, i'm wondering if there's more adequate out there missed.

kind regards, , in advance,

willem

update

to set more succinctly:

i need strtodate (or strtodatetime), added alternative of specifying exact format should utilize convert string tdatetime.

i created such routine freepascal's dateutils unit, , should easy port, if porting needed @ all.

code:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/rtl-objpas/src/inc/dateutil.inc?revision=30628&view=co

(code lastly (huge) procedure @ end of file)

documentation:

http://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html

note not finish inverse of formatdatetime, , has extensions:

an inverse of formatdatetime not 100% inverse, because 1 can set e.g. time tokens twice in format string,and scandatetime wouldn't know time pick.

strings hn can't reversed safely. e.g. 1:2 (2 minutes after 1) delivers 12 parsed 12:00 , misses chars "n" part.

trailing characters ignored. no back upwards eastern asian formatting characters since windows only. no mbcs support.

extensions

#9 eats whitespace. whitespace @ end of pattern optional. ? matches char. quote above chars match char.

(i believe these comments outdated in sense hat asian back upwards added later not sure)

delphi delphi-5

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -