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

22 Answered Questions

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

62 Answered Questions

[SOLVED] In C#, how do I calculate someone's age based on a DateTime type birthday?

  • 2008-07-31 23:40:59
  • Jeff Atwood
  • 629497 View
  • 1913 Score
  • 62 Answer
  • Tags:   c# .net datetime

42 Answered Questions

[SOLVED] How to get the current time in Python

  • 2009-01-06 04:54:23
  • user46646
  • 3417971 View
  • 3031 Score
  • 42 Answer
  • Tags:   python datetime time

39 Answered Questions

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

12 Answered Questions

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

63 Answered Questions

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

39 Answered Questions

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

20 Answered Questions

[SOLVED] Converting string into datetime

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

13 Answered Questions

[SOLVED] Convert UTC datetime string to local datetime

11 Answered Questions

[SOLVED] Convert UTC/GMT time to local time

  • 2008-10-07 19:23:05
  • rbrayb
  • 416097 View
  • 307 Score
  • 11 Answer
  • Tags:   c# .net datetime utc

Sponsored Content