日期时间格式转换 [英] DateTime Format Conversion

查看:85
本文介绍了日期时间格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个字符串变量,它以

Hi All,

I have string variable which hold the Date in

MM/dd/yyyy HH:mm:ss

格式保存日期.我想转换为

format.and want to convert into

dd/MM/yyyy HH:mm:ss

推荐答案

Don''t.而是使用用户当前的DateTime设置或绝对字符串将其转换为DateTime.然后将其保留为DateTime,直到您实际需要对其进行格式化以进行显示,然后将其转换为:
Don''t. Instead, convert it to a DateTime using either the users current DateTime settings or an absolute string. Then keep it as a DateTime until you actually need to format it for a display, and convert it then:
string date = "01/11/2011 13:24:17";
DateTime dt;
if (DateTime.TryParseExact(date, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture,DateTimeStyles.None , out dt))
    {
    ...
    }


string output = dt.ToString("dd/MM/yyyy HH:mm:ss");


Try this

Convert.ToDateTime(DateFrom.SelectedDate).ToString("yyyyMMdd")

and this to convert the date time to string with your special format

string CurrentTime = DateTime.Now.ToString("ddMMyyyy")




并且您可以看到我的答案 [




and you can see My answer[^] when i answer your friend before


尝试一下

Try this

string date = "01/11/2011 13:24:17";
string  dt = Convert.ToDateTime(date).ToString("dd/MM/yyyy hh:mm:ss");


这篇关于日期时间格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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