-1

I have stored DateTimeOffset into a text file like below,

DateTimeOffset.Now.ToString()

I noticed that it's stored as "8/13/2020 2:11:31 PM +05:30", not sure why it's adding +05:30 and how can I remove it to +00:00.

I have other DateTimeOffset saved into database and it's returns as +00:00 and in below snap x is actually smaller than z, but it's going wrong here. The reason I am saving to text file add offset as +05:30.

How to fix this issue, database side I don't have any control and while saving into text file, how to can I eliminate to store time without offset?

  • value for `x' coming from database
  • value for z coming from text file read

enter image description here

user584018
  • 10,186
  • 15
  • 74
  • 160
  • Use `UtcNow` instead of `Now` and you'll get the time in UTC, where the offset is always `00:00`. – Martin Costello Aug 13 '20 at 08:54
  • UtcNow, I can't use – user584018 Aug 13 '20 at 08:56
  • Are you trying to establish one date before another? If so use ticks instead – Darren Street Aug 13 '20 at 09:00
  • If you want to store the _local_ time without the offset, then why are you using `DateTimeOffset` in the first place? Use `DateTime` instead: `DateTime.Now.ToString()`. Or if you have to use `DateTimeOffset`, you could do: `DateTimeOffset.Now.ToString("M/d/yyyy h:mm:ss tt")`. If on the other hand, you want to display the UTC time, then use `UtcNow`; why can't you use it? – 41686d6564 stands w. Palestine Aug 13 '20 at 09:10

1 Answers1

1

You could use storedTime.DateTime then it is +00:00

TraderMoe
  • 84
  • 5
  • it's ignore time, which is important for me – user584018 Aug 13 '20 at 08:59
  • Ah okay then I missunderstood. In this case you should be able to call storedTime.DateTime. Then the Offsett should be gone (https://stackoverflow.com/questions/37257964/remove-time-zone-offset-from-datetimeoffset) – TraderMoe Aug 13 '20 at 09:16