0

I want to pass datetime from client to server. I prefer to pass in ISO format using .toISOString() method. The challenge is while passing datetime(Javascript) to server, if I used C# DateTime then it tries to convert datetime in local datetime. So to get it as in UTC I am using DateTimeOffset. But by this I am not able to get exactly what was client's offset.

  1. In which format I should pass datetime to server so I can retain offset of client or should I pass it separately?
  2. suppose in input text I am selecting 2022-02-11(YYYY-MM-YY) Time - 10:00 AM, Now I want to pass same datetime to server, how I can?
AABhatt
  • 25
  • 1
  • 5
  • 1
    The `toISOString` method returns a string which includes the `Z` suffix to indicate that it's a UTC value. If you use `DateTimeOffset` to parse that, it should automatically be parsed as a UTC value. – Richard Deeming Feb 11 '22 at 10:56
  • @RichardDeeming Yes, But In that case I will not have offset of client, How I can get that, like UTC+5:30? – AABhatt Feb 11 '22 at 11:54
  • @RichardDeeming Should I pass offset separately? – AABhatt Feb 11 '22 at 11:57
  • Yes, I think you'll need to pass it separately - [the `date.getTimezoneOffset` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset) is probably what you're looking for. But remember, the value returned from `toISOString` will *always* be the UTC value. – Richard Deeming Feb 11 '22 at 12:00
  • @RichardDeeming Can you please help me in my second question? I want pass same date which I asked through UI like 2022-02-11 10:00, how I can pass same to server? – AABhatt Feb 11 '22 at 12:37

0 Answers0