Coldfusion日期转换将yyyy-mm-dd:hh:mm:ss转换为日期和时间

时间:2020-03-27 19:01:32

标签: datetime coldfusion

我有这样的约会:

2020-02-09:08:57:51

如何将其转换为正确的日期和时间。

我尝试过#PARSEDATETIME(myd,"yyyy-MM-dd:HH:mm:ss")#

,但它返回{ts '2024-09-09 08:00:51'},这显然是错误的。

1 个答案:

答案 0 :(得分:5)

类似于dateTimeFormat,您必须在几分钟内使用其他字符:n

ts = "2020-02-09:08:57:51";
dt = parseDateTime(ts, "yyyy-mm-dd:HH:nn:ss");

writeOutput(dt);
// {ts '2020-02-09 08:57:51'}

dt是一个日期对象,它的toString实现在ColdFusion中返回ODBC时间戳文字。

文档仅供参考,以供将来参考:

d: Day of the month as digits; no leading zero for single-digit days.
dd: Day of the month as digits; leading zero for single-digit days.
EEE: Day of the week as a three-letter abbreviation.
EEEE: Day of the week as its full name.
m: Month as digits; no leading zero for single-digit months.
mm: Month as digits; leading zero for single-digit months.
mmm: Month as a three-letter abbreviation.
mmmm: Month as its full name.
M: Month in year.
D: Day in year.    yy: Year as last two digits; leading zero for years less than 10.
yyyy: Year represented by four digits.
YYYY: Week year represented by four digits.
Y: Week year.
YY: Week year as last two digits; leading zero for years less than 10.
G: Period/era string. (e.g. BC, AD)
h: hours; no leading zero for single-digit hours (12-hour clock)
hh: hours; leading zero for single-digit hours (12-hour clock)
H: hours; no leading zero for single-digit hours (24-hour clock)
HH: hours; leading zero for single-digit hours (24-hour clock)
n: minutes; no leading zero for single-digit minutes
nn: minutes; a leading zero for single-digit minutes
s: seconds; no leading zero for single-digit seconds
ss: seconds; leading zero for single-digit seconds
l or L: milliseconds, with no leading zeros
t: one-character time marker string, such as A or P
tt: multiple-character time marker string, such as AM or PM
w: Week of the year as digit.
ww: Week of the year as digits. Leading zero for single-digit week.
W: Week of the month as digit.
WW: Week of the month as digits. Leading zero for single-digit week.
相关问题