I am getting GMT DateTime as string input. For example
SampleDate = "20170221T085258.732 GMT"
Now, I want to convert this to datetime object. What is the best way of doing this conversion?
I am getting GMT DateTime as string input. For example
SampleDate = "20170221T085258.732 GMT"
Now, I want to convert this to datetime object. What is the best way of doing this conversion?
You just need to use ToLocalTime() Then you can change it to whatever timezone you care about.
DateTimeOffset.Parse(SampleDate).ToLocalTime();
var offset = new Date().getTimezoneOffset();
To remove the GMT and time zone, change the following line:
document.write(d.toString().replace(/GMT.*/g,""));
Hi try this code using DateTime.ParseExact()
string SampleDate=""20170221T085258.732 GMT";
DateTime dateObject = DateTime.ParseExact(SampleDate,"ddd MMM dd yyyy HH:mm:ss 'GMT'zzz", System.Globalization.CultureInfo.InvariantCulture);
For more info heres the link for DateTime.ParseExact
MSDN: https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx
Below code worked for me. Date contain some unwanted characters like "T",".","GMT" , once I removed those, it started working..
But I feel that, there has to be some better solution for this.
//I can write a regular expression to keep only numeric values and avoid this replacements...
SampleDate = "20170221T085258.732 GMT"
SampleDate = SampleDate.Replace("GMT", "")
SampleDate = SampleDate.Replace("T", "")
SampleDate = SampleDate.Replace(".", "")
Dim dateObject As DateTime = DateTime.ParseExact(SampleDate.Trim(), "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.InvariantCulture)