Sep-16-2019, 09:26 AM
(Aug-28-2019, 09:12 PM)avorane Wrote: Hello,
Can you try this?
Best Regards,
123456789101112131415161718192021222324252627282930from
datetime
import
datetime
import
math
old_date
=
"2019-08-06T07:37:51.358999986Z"
(
"old date: {}"
.
format
(old_date))
splited_date
=
old_date.split(
'.'
)
old_date_without_milliseconds
=
splited_date[
0
]
old_date_milliseconds
=
splited_date[
1
][:
-
1
]
(
"old_date_without_milliseconds: {}"
.
format
(old_date_without_milliseconds))
(
"old_date_milliseconds: {}"
.
format
(old_date_milliseconds))
new_bytes
=
[
0xc8
,
0xdc
,
0xac
,
0xa1
]
t
=
datetime.strptime(old_date_without_milliseconds,
"%Y-%m-%dT%H:%M:%S"
)
t
=
t.timestamp()
(
"Time stamp from old_date_without_milliseconds: {}"
.
format
(t))
t
=
int
(t)
*
1000000000
+
int
(old_date_milliseconds)
(
"Time stamp total * 1000000000: {}"
.
format
(t))
t
=
hex
(t)
(
"Time stamp total in hex: {}"
.
format
(t))
size_new_bytes
=
len
(new_bytes)
*
2
t
=
t[:
-
size_new_bytes]
for
b
in
new_bytes:
t
+
=
hex
(b)[
2
:]
(
"Time stamp in hex after substitution: {}"
.
format
(t))
t
=
int
(t,
16
)
(
"Time stamp after substitution: {}"
.
format
(t))
partie_entiere
=
math.floor((t
/
1000000000
))
*
1000000000
decimals
=
t
-
partie_entiere
t
=
datetime.fromtimestamp(partie_entiere
/
1000000000
)
t
=
datetime.strftime(t,
"%Y-%m-%dT%H:%M:%S."
)
+
str
(decimals)
+
"Z"
(
"new date: {}"
.
format
(t))
Nicolas TATARENKO
Hi Nicolas,
i'm back, i'm still stucked on this problem. But now i have an additional information: the new timestamps should differ from the others by a time close to 1 second. It's not always exactly a second, but it's a good way to test if the code works. Do you think this info may be useful to find out the solution? Also, with your code, sometimes the result is a timestamp with 1973 year, instead of 2019.
Thank you again for your support