DateTime.ToString()? [英] DateTime.ToString()?

查看:61
本文介绍了DateTime.ToString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题。如何正确显示日期的文本?

I am having a problem. How do I show the text of my Date correctly?

使用 DateTime.Now 我可以接收日期了&计算机时钟设置为当前时间的时间,但是,当我尝试解析为字符串格式时,它也显示日期,例如:12-04-2012 12:38 但是,我试图获取时间字符串,仅像 12:38

using DateTime.Now I was able to recieve the date & time the computers clock is set to currently, however, when I try to parse into a string format, it also shows the date like: 12-04-2012 12:38 but I was trying to get the time string only, like 12:38 only?

到目前为止,我尝试的是 Console.WriteLine(DateTime。 Now.ToString( 00:00:00));

What I tried so far was Console.WriteLine(DateTime.Now.ToString("00:00:00"));

但它不起作用= /

推荐答案

DateTime 具有 ToShortTimeString 定义的方法:

DateTime has a ToShortTimeString method defined:

DateTime.Now.ToShortTimeString()

或者,您可以使用自定义格式字符串

DateTime.Now.ToString("HH:mm")

或者,使用标准格式字符串短时间格式

Alternatively, use the standard format string for short time format:

DateTime.Now.ToString("t")

这篇关于DateTime.ToString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆