日期格式 [英] DateFormat

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

问题描述

我正在获取格式为"dd/mm/yyyy"的日期字符串.代码为DateTime.Today.ToShortDateString();

I am getting the date string in the format "dd/mm/yyyy" for the code DateTime.Today.ToShortDateString();

即使将区域设置更改为其他国家/地区.

Even if changed the regional settings to different country.

但我想将格式设为"mm/dd/yyyy".

But I would like to get the format as "mm/dd/yyyy". Where to change the settings.

推荐答案

希望这可以解决您的问题.

hope this solves your problem..

今天的DateTime = DateTime.Now;

DateTime today = DateTime.Now;

DateTimeFormatInfo dateFormat = DateTimeFormatInfo();

DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();

dateFormat.ShortDatePattern ="MM/dd/yyyy";

dateFormat.ShortDatePattern = "MM/dd/yyyy";

字符串 todayAsString = today.ToString("d",dateFormat);

string todayAsString = today.ToString("d",dateFormat);


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

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