日期格式转换 [英] date format convertion

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

问题描述

string date = calarc.SelectedDate.ToString("MM/dd/yyyy");

其中calarc为压延机的控制。

where calarc is calender control.

它返回2009年3月14日格式的日期,但我想在2009年3月14日的格式。

It returns a date in 03-14-2009 format but i want it in 03/14/2009 format.

让我怎么做上面?

推荐答案

我觉得你目前的文化与格式搞乱。尝试

I think your current culture is messing with format. Try

DateTime.Parse("2009-03-14").ToString(@"MM/dd/yyyy", CultureInfo.InvariantCulture)

,因为它似乎/是真的为隔板的语法(类似于至M,D,Y或任何其他)。这就是为什么它被用在培养指定的分隔符代替。这是在<著名href=\"http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.dateseparator%28VS.71%29.aspx\"相对=nofollow>文档了。

如果自定义模式包括
  格式模式/,则DateTime.ToString
  显示DateSeparator在价值
  发生在格式/的
  格局。

If the custom pattern includes the format pattern "/", DateTime.ToString displays the value of DateSeparator in place of the "/" in the format pattern.

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

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