Displaying and Manipulating the date function

Displaying and Manipulating the date function

  • Displaying and manipulating a date function variable can something be a bit of pain especially when you need to change the date format from dd/MM/yyyy to yyyy-MM-d or worst still change this to different time-zone.
  • Fortunately for us there a function called Date.parse in C# which can convert a string to date time format
  • An example of this:-
    •  CultureInfo nz = new CultureInfo(“en-NZ”);
       CultureInfo us = new CultureInfo(“en-US”);
      dateformated = “2015-“+01+”-“+28;
      DateYear = DateTime.ParseExact(dateformated, “yyyy’-‘MM’-‘dd”, nz);
  • Using this function you can easily change to different time zone, to us time zone
  • DateTime.ParseExact actually take the time format for your local computer setting. To change this on a windows machine you would need to change the time from the control panel -> regional -> time

 

Leave a Reply

Your email address will not be published. Required fields are marked *