Class for Dateformat in C#

Most of time we Convert date according to our requirement . So below code snippet defines a way to Convert date to some usual format.

Here it defines class name as dateformat, in this class there are three funtion named GetDtMmddYY, GetdtDDmmyy, Getdateformat having parameter of Type string . These functions returns string value(date in different format).

  1. /// <summary>  
  2. ////////////////////////////////////////////////////////////////////////////////  
  3. // Description: Class for Dateformat.  
  4. // Created By: Ajeet Mishra  
  5. // Created On: September 1 2015  
  6. ///////////////////////////////////////////////////////////////////////////////  
  7. /// </summary>  
  8. using System;  
  9. using System.Collections.Generic;  
  10. using System.Linq;  
  11. using System.Web;  
  12. public class dateformat {  
  13.     public dateformat() {}  
  14.     public string GetDtMmddYY(string date) {  
  15.         string day = date.Substring(0, 2);  
  16.         string month = date.Substring(3, 2);  
  17.         string year = date.Substring(6, 4);  
  18.         string dayslac = string.Concat(day, '/');  
  19.         string monthslac = string.Concat(month, '/');  
  20.         string m = string.Concat(monthslac, dayslac);  
  21.         string y = string.Concat(m, year);  
  22.         return y;  
  23.     }  
  24.     public string GetdtDDmmyy(string dt) {  
  25.         DateTime date = Convert.ToDateTime(dt);  
  26.         // DateTime dateTime = DateTime.UtcNow.Date;  
  27.         return date.ToString("dd/MM/yyyy");  
  28.     }  
  29.     public string Getdateformat(string dt) {  
  30.         DateTime date = Convert.ToDateTime(dt);  
  31.         string year = date.Year.ToString();;  
  32.         int month = Convert.ToInt32(date.Month);  
  33.         int day = Convert.ToInt32(date.Day);  
  34.         string dayslac = "", monthslac = "";  
  35.         if (day <= 9) {  
  36.             dayslac = string.Concat('0', day.ToString(), '/');  
  37.         } else {  
  38.             dayslac = string.Concat(day.ToString(), '/');  
  39.         }  
  40.         if (month <= 9) {  
  41.             monthslac = string.Concat('0', month.ToString(), '/');  
  42.         } else {  
  43.             monthslac = string.Concat(month.ToString(), '/');  
  44.         }  
  45.         string dm = string.Concat(dayslac, monthslac);  
  46.         string y = string.Concat(dm, year);  
  47.         return y;  
  48.     }  
  49. }