本文介绍了使用C#如何将字符串传递到日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有字符串"07-12-12 09:40 AM",其格式为"mm-dd-yy",但我需要将其格式设置为"yy-mm-dd".


i have string "07-12-12 09:40AM",it''s format "mm-dd-yy",but i need to format for "yy-mm-dd".
how could i do?

推荐答案


string str = "07-12-12 09:40AM";
IFormatProvider culture = new CultureInfo("en-us", false);
DateTime dt = DateTime.Parse(str, culture);



私有字符串GetDateResult()
{
字符串dateString ="07-12-13 09:40 AM";
字符串strResult =";

DateTime dateResult;
CultureInfo文化= CultureInfo.CreateSpecificCulture("en-US");
DateTimeStyles样式= DateTimeStyles.None;
如果(DateTime.TryParse(dateString,culture,styles,out dateResult))
strResult = dateResult.ToString("yy-MM-dd");

返回strResult;
}

请使用此功能.也许可以为您提供帮助.

private string GetDateResult()
{
string dateString = "07-12-13 09:40AM";
string strResult = "";

DateTime dateResult;
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
DateTimeStyles styles = DateTimeStyles.None;
if (DateTime.TryParse(dateString, culture, styles, out dateResult))
strResult = dateResult.ToString("yy-MM-dd");

return strResult;
}

Use this function pls.Maybe could help you.


这篇关于使用C#如何将字符串传递到日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 04:58