Created
May 27, 2019 13:30
-
-
Save WesleyBatista/9db8475ec65f559c9a37ac7d5436a6e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dateutil.parser | |
dates = [ | |
# dates that comes as str from kafka message: | |
'2019-05-27T12:54:28.777652636Z', | |
'2019-05-27T12:54:28.128Z', # added | |
'2019-05-27T12:54:28.120Z', # added | |
'2019-05-27T12:54:28.100Z', # added | |
'2019-05-27T12:54:28.1Z', # added | |
'2019-05-27T12:54:29.993908166Z', | |
] | |
def parser_current(dt): | |
return int(str(dt.timestamp()).replace('.', '')) | |
def parser_1(dt): | |
return str(int(dt.timestamp())) + dt.strftime('%f') | |
def parser_2(dt): | |
return int(dt.timestamp() * 1000000) | |
for item in dates: | |
print(f'running for "{item}"') | |
dt = dateutil.parser.parse(item) | |
print(f'parser_current() {parser_current(dt)}') | |
print(f'parser_1() {parser_1(dt)}') | |
print(f'parser_2() {parser_2(dt)}') | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output: