gpt4 book ai didi

c# - 如何在不带前导零的情况下从 C# DateTime 获取小时数?

转载 作者:可可西里 更新时间:2023-11-01 08:17:40 25 4
gpt4 key购买 nike

DateTime now = DateTime.Now;
string time = now.ToString("h");

错误提示我应该先解析字符串。当前时间是 3 我不想要 03 我只想要 3。"hh" 返回 03 但我不能简单地使用 "h".

最佳答案

System.DateTime.Now.ToString("%h")

你必须 specify that the format is custom .

关于c# - 如何在不带前导零的情况下从 C# DateTime 获取小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027191/

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