FormatDateTime的反函数 [英] Inverse function of FormatDateTime
问题描述
我正在寻找一个功能来反转任何字符串( YYYYMDD
, YY / MM / DD $由,
YYMMDD
,...) = FormatDateTimerel =noreferrer> FormatDateTime 到datetime。
I am looking for a function to reverse any string (YYYYMDD
,YY/MM/DD
,YYMMDD
,...) created by the function FormatDateTime to datetime.
示例
我有格式为 YYYYMMDD
的字符串日期由 FormatDateTime
I have a string-date in format YYYYMMDD
created by FormatDateTime
mydatestr:=FormatDateTime('YYYYMMDD',Mydate);
现在我如何将mydatestr转换为 DateTime
now how I can convert mydatestr to DateTime
again?
更新
这些功能
function StrToDate(const S: string): TDateTime; overload;
function StrToDate(const S: string;
const FormatSettings: TFormatSettings): TDateTime; overload;
function StrToDateTime(const S: string): TDateTime; overload;
function StrToDateTime(const S: string;
const FormatSettings: TFormatSettings): TDateTime; overload;
不支持传递一个带有转换格式的字符串。
does not support passing a string with the format to convert.
我看起来像这样
Mydatetime:=InvFormatDatetime('20091225','yyyymmdd');
或
Mydatetime:=InvFormatDatetime('20090108','yyyyddmm');
推荐答案
现有的解决方案很容易,StrToDateFmt函数RX包中的rxDateutil.pas单元,可以从这里下载: http://sourceforge.net/projects/rxlib /
It is quite easy with existing solution, StrToDateFmt function in rxDateutil.pas unit from RX package, which can be downloaded here: http://sourceforge.net/projects/rxlib/
编辑:
上面提到的功能和来自rxDateutil.pas的StrToDateFmt正在做什么您希望,使用指定的字符串掩码将字符串转换为datetime,代码太大,无法包含,因为此单元还包含其他日期函数,其中一些需要将字符串转换为日期。
Mentioned above function and StrToDateFmt from rxDateutil.pas are doing exactly what you expect, converting string to datetime using specified string mask, the code is too large to be included as this unit contains also other date functions, some of them required for converting string to date.
使用示例:
Result := StrToDateFmtDef('MM/DD/YYYY', '11/11/2011', Now);
这篇关于FormatDateTime的反函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!