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 ))
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:
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:
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.