.NET DateTime转换为String [英] .NET DateTime to String

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

问题描述

是否有一种简单的方法可以将DateTime对象转换为这样的字符串表示形式'2010-03-03 10:38:48'.

Is there a easy way to convert a DateTime object to a string representation like this '2010-03-03 10:38:48'.

我不确定上面的格式是什么,但是它与通过ToLongTimeString()等获得的模式不同.

I'm not sure what the above format is but it is different from the patterns obtainable via ToLongTimeString() etc.

这是字符串生成器的一种情况吗?

Is this a case for string builder?

推荐答案

像这样:

date.ToString("yyyy-MM-dd hh:mm:ss")

如果要24小时工作,请将 hh 替换为 HH .

If you want 24 hour time, replace hh with HH.

有关更多信息,请参见此处.

For more information, see here.

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

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