-
Dec 7th, 2021, 11:01 AM
#1
[RESOLVED] convert date timespan with regional time
Hi.
I have a time string this: /Date(1644012000000+0200)/
Now I have 2 issue
1)If i remove the extra time I get a wrong time doing this:
Code:
Dim dtest As DateTime = "1/1/1970"
dtest = dtest + TimeSpan.FromMilliseconds(Convert.ToDouble(strvistadate))
Mind you I'm removing the strings and leave only the number portion (1644012000000) or if I add the + 0200 : 1644012000200
This is supposed to give out 2022-02-05 but it's giving 2022-02-04 . So I'm missing a day.
I haven't dealt with regional addition so I'm not sure how would I use the extra +0200 .
Even with a datetimeoffset it will not work:
Code:
Dim dtest As DateTimeOffset = "1/1/1970"
dtest = dtest + TimeSpan.FromMilliseconds(Convert.ToInt64("1644012000200"))
Dim correctdate As Date = dtest.Date.ToString
So I guess somehow I need to add the extra +0200 but it's not an just an addition on the timestamp, it's something else.
Thanks.
EDIT:
Best bet I found so far is get the +0200 , treat it as an additional hour.
dtest = dtest + TimeSpan.FromMilliseconds(Convert.ToDouble("1644012000200")) + TimeSpan.FromHours(2)
That seems lame. Isn't there something to detect the hours or I should just put a detection mechanism in a function?
Thanks
Last edited by sapator; Dec 7th, 2021 at 11:08 AM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Dec 7th, 2021, 11:45 AM
#2
Re: convert date timespan with regional time
This produces 2/5/2022
Code:
Dim dtest As DateTime = #1/1/1970#
dtest = dtest + TimeSpan.FromMilliseconds(1644012000000) + TimeSpan.FromHours(2)
-
Dec 7th, 2021, 11:50 AM
#3
Re: convert date timespan with regional time
The +200 part could be written as +2:00 (ie: 2 hours and 0 minutes), I'm don't know why the standard is without the colon.
Note that some time zones aren't exact hours (eg: +0030 is possible), so you do need to detect both parts and add them as time.
A separate function to do that is probably wise.
-
Dec 7th, 2021, 11:51 AM
#4
Re: convert date timespan with regional time
if I add the + 0200 : 1644012000200
Yeah, stop doing that... the +0200 shows the hour offset from UTC, typically representing the timezone. For example I'm in the Eastern TZ, which is UTC-5 (or-4 depending on the time of year & DST) In this case it's UTC +2 so simply adding 200 to your milliseconds isn't the answer.
TimeSpan.FromMilliseconds(Convert.ToDouble("1644012000200")) + TimeSpan.FromHours(2)
That's closer ... but it should still only affect the hours portion of the dateTime, not the Date ... you should be coming out with the correct date at least (I think). Unless because it's +2 you need to add a day. ????
Honestly I'm not 100% sure...
Here's an SO thread where someone had a similar problem ... and there's a solution
-tg
-
Dec 7th, 2021, 12:31 PM
#5
Re: convert date timespan with regional time
Originally Posted by techgnome
Yeah, stop doing that... the +0200 shows the hour offset from UTC, typically representing the timezone. For example I'm in the Eastern TZ, which is UTC-5 (or-4 depending on the time of year & DST) In this case it's UTC +2 so simply adding 200 to your milliseconds isn't the answer.
That's closer ... but it should still only affect the hours portion of the dateTime, not the Date ... you should be coming out with the correct date at least (I think). Unless because it's +2 you need to add a day. ????
Honestly I'm not 100% sure...
Here's an SO thread where someone had a similar problem ... and there's a solution
-tg
Originally Posted by si_the_geek
The +200 part could be written as +2:00 (ie: 2 hours and 0 minutes), I'm don't know why the standard is without the colon.
Note that some time zones aren't exact hours (eg: +0030 is possible), so you do need to detect both parts and add them as time.
A separate function to do that is probably wise.
I think we all agree that this isn't a standard format. My understanding is that Unix timestamps are time zone independent, they are by definition UTC times.
-
Dec 7th, 2021, 01:03 PM
#6
Re: convert date timespan with regional time
I will have to ask the company I get the data from if they have this format.
All those years they did not gave out a region time but suddenly they do.
Thank you all.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|