如何更改日期格式? [英] how do i change date format??

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

问题描述

嘿,伙计们,

我有一个带有日期字段的表,该字段具有以
格式保存的日期 yyyy-mm-dd,我要实现的是当我显示它们时,希望它们以示例"2009年9月5日"的格式显示.有人可以帮我吗?

非常感谢.
Chetan

hey Guys,

I have a table with a date field that had date saved in the format of
yyyy-mm-dd, what i want to achieve is when I display them I want them to be displayed as an example "September 05 2009" format. can anybody help me with this??

Thank you very much.
Chetan

推荐答案

DateTime dt = new DateTime(2009,9,5);
            Console.WriteLine(dt.ToString("MMMM dd yyyy"));


创建一个DateTime对象,并尝试将日期时间解析为字符串格式.您可以使用以下代码:

Create a object of DateTime and try to parse the datetime in string to its format. You may use the code below :

DateTime dt = DateTime.ParseExact("2009-09-05", "yyyy-mm-dd");
Console.WriteLine(dt.ToString("MMMM dd yyyy"));




:)




:)


您可以将DateformatString绑定到Repeter绑定字段,例如,

You can Bind DateformatString to your Repeter Bound Field Like,

<asp:boundcolumn datafield="DateTime" dataformatstring="{0:MMMM dd yy}" />


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

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