By user1025852


2012-11-06 15:28:49 8 Comments

assume I have this string : How can I convert it to DateTimeOffset object that will have UTC time - means -00:00 as Time Zone - even if I run it on machine on a specific timezone?

Assume String: "2012-10-08T04:50:12.0000000"

Convert.ToDateTime("2012-10-08T04:50:12.0000000" + "Z");

--> DateTime d = {10/8/2012 6:50:12 AM} and I want it to be DateTime d = {10/8/2012 4:50:12 AM} as if it will understand I want the date as simple as it comes (BTW - my machine is in timezone +02:00)

1 comments

@Knaģis 2012-11-06 15:32:07

Use DateTimeOffset.Parse(string).UtcDateTime.

@alemus 2018-10-09 16:21:04

Do not know if something has changed in .NET since this was asked but I had to append ToString() to the end to get this to work, but it works perfectly DateTimeOffset.Parse(string).UtcDateTime.ToString()

Related Questions

Sponsored Content

18 Answered Questions

[SOLVED] How to convert local time string to UTC?

20 Answered Questions

[SOLVED] Converting string into datetime

  • 2009-01-21 18:00:29
  • Oli
  • 2784539 View
  • 2069 Score
  • 20 Answer
  • Tags:   python datetime

39 Answered Questions

[SOLVED] Should I use the datetime or timestamp data type in MySQL?

66 Answered Questions

[SOLVED] What is the difference between String and string in C#?

38 Answered Questions

[SOLVED] How do you get a timestamp in JavaScript?

11 Answered Questions

[SOLVED] Convert UTC/GMT time to local time

  • 2008-10-07 19:23:05
  • nzpcmad
  • 396630 View
  • 293 Score
  • 11 Answer
  • Tags:   c# .net datetime utc

9 Answered Questions

[SOLVED] How to make an unaware datetime timezone aware in python

15 Answered Questions

[SOLVED] How to sort an array by a date property

  • 2012-04-12 12:53:03
  • ryandlf
  • 597864 View
  • 653 Score
  • 15 Answer
  • Tags:   javascript datetime

9 Answered Questions

[SOLVED] DateTime vs DateTimeOffset

12 Answered Questions

[SOLVED] Convert UTC datetime string to local datetime

Sponsored Content