Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime without timezone

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.

like image 661
P_rnd Avatar asked Oct 16 '13 11:10

P_rnd


People also ask

How to get rid of timezone in DateTime?

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.

How do you make a Date without time zones?

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 .

How to remove time zone in Date time in Python?

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.


1 Answers

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
like image 122
Yaniv Avatar answered Oct 13 '22 06:10

Yaniv