Timestamp conversion

Hi all,
need some help with a timestamp conversion, can’t find it online how to convert.
Timestamp example : (20220220112530.708103-000)
here is the script:

from win32com.client import GetObject
objWMI = GetObject('winmgmts:\\\\.\\root\\default').InstancesOf('SystemRestore')

for obj in objWMI:
                if obj.SequenceNumber != None:
                    print(str(obj.SequenceNumber))
                    print(str(obj.Description ))
                    print(str(obj.CreationTime ))

Can anyone help me with this?
Thanks!

You don’t state to what you want to convert that date/time format.
If you want to parse 20220220112530.708103-000 into a Python time
tuple or a datetime object, then you should check out the
documentation for the strptime() in each of these modules:

https://docs.python.org/3/library/time.html#time.strptime
https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime

If you want to convert to something else, those are good
intermediary formats since you can then use strftime() to reformat
them however you need.

hi fungi,
thank you for taking the time to answer this.

just want it convert to d-m-Y hh:mm, but i can’t find an example with the timestamp generated by the script.

The official Python documentation, to which I linked in my first
reply, explains how to do it in great detail. If the problem is that
English isn’t your first language, you can find a drop-down in the
top left corner of the page with translations into seven other
languages.

I’m all about teaching people to fish rather than just giving them
fish, since you’re really not going to learn Python well just by
copying and pasting examples from others who have done your work for
you. However, on the assumption you’re really struggling and not
simply looking for someone to write your program for free, I’ll show
you how I’d do it:

>>> import time
>>> original = "20220220112530"
>>> parsed = time.strptime(original, "%Y%m%d%H%M%S")
>>> reformatted = time.strftime("%d-%m-%Y %H:%M", parsed)
>>> reformatted
'20-02-2022 11:25'

Obviously, stripping off the parentheses, subseconds and timezone
are left as an exercise for the reader but can be accomplished with
trivial string operations. If you want to perform timezone
conversions, that’s also possible with some additional steps.

Hopefully this helps, though I strongly encourage you to review the
documentation for the time module from Python’s standard library and
try to at least understand how my example works.

thanks, you’re right about the language. Find it really hard to understand the python documentation. Most of the time i find the answer on stackoverflow…
Searched the internet for hours to find a solution. Did not know that you can easily strip down parentheses, subseconds and timezone. Came across many of these examples, wondering why my date is so different. :thinking:

I am glad that you showed me this.

Thanks a lot