且构网

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

如何从字符串中的日期时间仅获取月份和日期

更新时间:2023-11-05 12:26:52

以格式字符串编写的内容将从日期中提取.

 System.DateTime.Now.ToString(" );
System.DateTime.Now.ToString(" );
System.DateTime.Now.ToString(" ); 


尝试如下:
DateTime myDateTime = DateTime.Now;
       string month = myDateTime.Month.ToString();
       string year = myDateTime.Year.ToString();


使用此
 字符串 myDate = System.DateTime.Now.ToString("  MM yy"); 


my string for getting DateTime is like this:

string myDate = System.DateTime.Now.ToString("MM/dd/yyyy");


If I want to obtain all values of dates of month, how can I exclude the day from above string.
Please help with the code.

With regards,
bishnu

whatever you will write in format string will be extracted from the date like.

System.DateTime.Now.ToString("MM yy");
System.DateTime.Now.ToString("MMM yyyy");
System.DateTime.Now.ToString("MM/yyyy");


try as follows:
DateTime myDateTime = DateTime.Now;
       string month = myDateTime.Month.ToString();
       string year = myDateTime.Year.ToString();


use this
string myDate = System.DateTime.Now.ToString("MM yy");