11

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.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
P_rnd
  • 153
  • 1
  • 1
  • 11
  • 2
    What *exactly* do you mean by "with offset time zone"? Please show your code, what you expected to receive, and what you actually received. And consider using `DateTimeOffset`. – Jon Skeet Oct 16 '13 at 11:23
  • Please see my update in a question – P_rnd Oct 16 '13 at 12:11

4 Answers4

40

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
Yaniv
  • 966
  • 12
  • 20
6

you can try this.

DateTimeOffset.Parse("2013-07-22T08:51:38.000-07:00").DateTime.ToString("dd-MM-yyyy hh:mm:ss tt");

Ram Nivas
  • 142
  • 3
  • 13
1

You can try the below one

        string s = "2013-07-22T08:51:38.000-07:00";

        DateTime d = Convert.ToDateTime(s);

        Console.WriteLine(d.Date.ToShortDateString());
Gun
  • 1,400
  • 1
  • 10
  • 16
-3

If you have a DateTime object, you can use the Date property on it to receive just the date.

adamjc
  • 118
  • 6