加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何从C#DateTime获取小时,而不带零?

发布时间:2020-12-15 03:53:48 所属栏目:百科 来源:网络整理
导读:DateTime now = DateTime.Now; string time = now.ToString("h"); 错误地说我应该首先解析字符串.目前的时间是3我不想要03我只想要3.“hh”返回03,但我不能简单地使用“h”. 解决方法 System.DateTime.Now.ToString("%h") 你必须要specify that the format i
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读