gpt4 book ai didi

c# - 将字符串转换为日期时间给出了错误的结果

转载 作者:太空宇宙 更新时间:2023-11-03 19:48:40 25 4
gpt4 key购买 nike

我正在尝试将字符串转换为 DateTime 对象,如下所示:

DateTime.ParseExact("31/12/2017","dd/mm/yyyy",CultureInfo.InvariantCulture);

但我得到的是 DateTime 月数 = 1 而不是 12 !!

Date = {1/31/2017 12:00:00 AM}

最佳答案

日期格式字符串使用月份的分钟数。使用 MM 表示月份。 mm 代表分钟。

"mm" The minute, from 00 through 59.
"MM" The month, from 01 through 12.

引用:Custom Date and Time Format Strings

这意味着您需要将代码段更新为...

DateTime.ParseExact("31/12/2017","dd/MM/yyyy",CultureInfo.InvariantCulture);

关于c# - 将字符串转换为日期时间给出了错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42404217/

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