I have date in string: "2013-07-22T08:51:38.000-07:00"
When I try parse this string, I receive date with offset of timezone.
How can I make it without timezone offset?
---UPDATE---
it is that I receive: DateTime.Parse("2013-07-22T08:51:38.000-07:00") = 7/22/2013 7:51:38 PM
but I need to receive 7/22/2013 8:51:38 AM
- DateTime without offset.
The solution is to convert your datetime. datetime object to UTC (so everything in your database is UTC since it can't specify timezone) then either insert it into the database (where the timezone is removed anyway) or remove it yourself.
To create a Date without the timezone, we called the toISOString method on the Date object and removed the character Z from the ISO string. The Date object shows the exact same time as the one stored in the dateStr variable - 09:35:31 .
To remove timestamp, tzinfo has to be set None when calling replace() function. First, create a DateTime object with current time using datetime. now(). The DateTime object was then modified to contain the timezone information as well using the timezone.
You can use the DateTime property of DateTimeOffset.
Example:
string s = "2013-07-22T08:51:38.000-07:00";
var dateTimeOffset =DateTimeOffset.Parse(s, null);
Console.WriteLine(dateTimeOffset.DateTime);
Outputs:
22/07/2013 08:51:38
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With