gpt4 book ai didi

scala - 仅显示 DateTime 值的年月日

转载 作者:行者123 更新时间:2023-12-02 07:01:15 26 4
gpt4 key购买 nike

我有这个代码:

order.bookingDate()

我明白了:2013-11-22T10:15:00.000-08:00

但我只想在网页中显示这个:2013-11-22,如果可以用这种格式:22-11-2013,任何想法?谢谢!

最佳答案

dateTime.ToString("yyyy-MM-dd");

如果字符串中有日期时间,则首先按如下方式将其转换为日期时间

DateTime dateTime;
dateTime = new DateTime();
dateTime = DateTime.ParseExact(MyString, "yyyy-MM-dd HH:mm tt", null);

日期格式

d - Numeric day of the month without a leading zero.
dd - Numeric day of the month with a leading zero.
ddd - Abbreviated name of the day of the week.
dddd - Full name of the day of the week.

M - Numeric month with no leading zero.
MM - Numeric month with a leading zero.
MMM - Abbreviated name of month.
MMMM - Full month name.

y - Year with out century and leading zero.
yy - Year with out century, with leading zero.
yyyy - Year with century.

时间格式

h - 12 Hour clock, no leading zero.
hh - 12 Hour clock with leading zero.
H - 24 Hour clock, no leading zero.
HH - 24 Hour clock with leading zero.

m - Minutes with no leading zero.
mm - Minutes with leading zero.

s - Seconds with no leading zero.
ss - Seconds with leading zero.

t - AM/PM but only the first letter.
tt - AM/PM ( a.m. / p.m.)

zz - Time zone off set with +/-

关于scala - 仅显示 DateTime 值的年月日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com