gpt4 book ai didi

c# - 想要在 yyyy-MM-ddTHH :mm:ss format but its type should be Datetime, 中使用日期时间在 C# 中是可能的

转载 作者:行者123 更新时间:2023-11-30 22:08:30 27 4
gpt4 key购买 nike

实际上,我正在调用一个接受日期时间参数但采用 YYYY-MM-DDThh:mm:ss 格式的 Web 服务方法,因此想使用 yyyy-MM-ddTHH:mm:ss 格式的日期时间,但类型应为日期时间,这在 C# 中可能吗?

最佳答案

Date内部并没有以string的形式存储,格式只是一种表现,所以不能强制DateTime对象的特定格式。您宁愿将其转换为您想要的格式。您可以将 DateTime 作为 Web 服务的参数并将其转换为您想要的格式,或者您可以使用 string 变量,该变量具有您将转换为 的特定格式的 DateTime >DateTime 对象使用 DateTime.ParseExact .

日期时间值及其字符串表示

Internally, all DateTime values are represented as the number of ticks (the number of 100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001. The actual DateTime value is independent of the way in which that value appears when displayed in a user interface element or when written to a file. The appearance of a DateTime value is the result of a formatting operation. Formatting is the process of converting a value to its string representation, MSDN.

关于c# - 想要在 yyyy-MM-ddTHH :mm:ss format but its type should be Datetime, 中使用日期时间在 C# 中是可能的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247047/

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