I want to convert date time to specify format that is
Wed Aug 01 2012 14:37:50 GMT+0530 (India Standard Time)
Actually i want to display th
If you do not want to hardcode the GMT offset and cannot rely on the local time being India Standard Time you can pull this information from the TimeZoneInfo
:
// get UTC from local time
var today = DateTime.Now.ToUniversalTime();
// get IST from UTC
var ist = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(today, "UTC", "India Standard Time");
// find the IST TimeZone
var tzi = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
// get the UTC offset TimeSpan
var offset = tzi.GetUtcOffset(today);
// determine the TimeSpan sign
var sign = offset.Ticks < 0 ? "-" : "+";
// use a custom format string
var formatted = string.Format(CultureInfo.InvariantCulture, "{0:ffffd MMM HH:mm:ss} GMT{1}{2:hhmm}", today, sign, offset);