Extract group of characters from an object/string

时间:2019-01-09 22:00:31

标签: business-objects webi

I have a very long string of characters that contain a date and time. How can I extract just the date part and the time part from it?

Here's the string: 0:2019010309130000:0.000000:126:0

I just need to extract the date and the time as in:

Date - 20190103 Time - 0913 and format it as 09:13

1 个答案:

答案 0 :(得分:0)

This applies to Python programming language.:

If the string stays in the same format I believe you should be able to extract it using a concept known as "slicing" (you can find more about it in here).

x = "0:2019010309130000:0.000000:126:0"
y = 'Date - {} Time - {}:{}'.format(x[2:10], x[10:12], x[12:14])
print(y)