且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转换int month&一年到一个月和一个月年

更新时间:2022-11-13 13:39:21

 CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(< int>)< /   int  >  





所以

  string  [] date =   08/2014  .Split('  /'); 
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(date [ 0 ]));


Convert.ToDateTime(08 01 2014)。ToString(MMM yyyy);


如果您的起始点是包含MM / yyyy的字符串,请使用 DateTime.TryParse [ ^ ] - 如果是两个数字,则使用日期时间构造函数,该日期时间构造函数需要年,月,日,并且每天使用1。



要将此转换为您想要的字符串 DateTime.ToString(@MMM yyyy) [ ^ ]

How to convert int month & year to string month & year.

like "08/2014" to "Aug 2014"




Thanks,

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(<int>)</int>



So

string[] date = "08/2014".Split('/');
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(date[0]));


Convert.ToDateTime("08 01 2014").ToString("MMM yyyy");


If your starting point is a string containing "MM/yyyy" convert it to a datetime using DateTime.TryParse[^] - if it is two numbers use the datetime constructor that takes year,month,day and use 1 for day.

To convert this to the string you want use DateTime.ToString(@"MMM yyyy")[^]