public static string GetDate(string testDate, int dateFormat)
{
DateTime dateTime;
string result = "";
if (!string.IsNullOrEmpty(testDate))
dateTime = Convert.ToDateTime(testDate);
else
dateTime = DateTime.Now;
if (!string.IsNullOrEmpty(testDate))
{
switch (dateFormat)
{
case 1:
return result = (DateTime.Today).ToString("MM/d/yyyy");
case 2:
if (!string.IsNullOrEmpty(testDate))
return result = testDate.Substring(4, 2) + "/" + testDate.Substring(6, 2) + "/" + testDate.Substring(0, 4);
else
return result;
case 3:
return result = Convert.ToDateTime(testDate).ToString("MM/dd/yyyy");
case 4:
return result = (DateTime.Today).ToString("yyyyMMdd");
case 5:
return result = Convert.ToDateTime(testDate).ToString("yyyyMMdd");
case 6:
//Added for display date in format yyyy-mm-dd and time.
return result = dateTime.ToString("u").Substring(0, dateTime.ToString("u").LastIndexOf("Z"));
case 7:
//Added for display date in format yyyy-mm-dd.
return result = dateTime.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
case 8:
//Added for display date in (g) General date/short time:. 9/1/2008 7:23 PM
return result = dateTime.ToString("g");
case 9:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy");
case 10:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy HH:mm");
case 11:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy hh:mm tt"); //MP_ITS@20121015:added for date formate 10-15-2012 15.00 PM
default: return result = "";
}
}
return result;
}
{
DateTime dateTime;
string result = "";
if (!string.IsNullOrEmpty(testDate))
dateTime = Convert.ToDateTime(testDate);
else
dateTime = DateTime.Now;
if (!string.IsNullOrEmpty(testDate))
{
switch (dateFormat)
{
case 1:
return result = (DateTime.Today).ToString("MM/d/yyyy");
case 2:
if (!string.IsNullOrEmpty(testDate))
return result = testDate.Substring(4, 2) + "/" + testDate.Substring(6, 2) + "/" + testDate.Substring(0, 4);
else
return result;
case 3:
return result = Convert.ToDateTime(testDate).ToString("MM/dd/yyyy");
case 4:
return result = (DateTime.Today).ToString("yyyyMMdd");
case 5:
return result = Convert.ToDateTime(testDate).ToString("yyyyMMdd");
case 6:
//Added for display date in format yyyy-mm-dd and time.
return result = dateTime.ToString("u").Substring(0, dateTime.ToString("u").LastIndexOf("Z"));
case 7:
//Added for display date in format yyyy-mm-dd.
return result = dateTime.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
case 8:
//Added for display date in (g) General date/short time:. 9/1/2008 7:23 PM
return result = dateTime.ToString("g");
case 9:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy");
case 10:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy HH:mm");
case 11:
return result = Convert.ToDateTime(testDate).ToString("MM-dd-yyyy hh:mm tt"); //MP_ITS@20121015:added for date formate 10-15-2012 15.00 PM
default: return result = "";
}
}
return result;
}
No comments:
Post a Comment