Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-commons
Commits
9e7442ff
Commit
9e7442ff
authored
Nov 13, 2024
by
Wei Shoulin
Browse files
random str
parent
db048085
Pipeline
#7312
passed with stage
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
csst_dfs_commons/convert/date_utils.py
View file @
9e7442ff
from
datetime
import
datetime
from
datetime
import
datetime
import
time
import
time
import
random
import
string
def
format_datetime
(
dt
):
def
format_datetime
(
dt
):
return
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
return
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
...
@@ -21,3 +23,11 @@ def format_time_ms(float_time):
...
@@ -21,3 +23,11 @@ def format_time_ms(float_time):
def
str_to_datetime
(
str_time
):
def
str_to_datetime
(
str_time
):
return
datetime
.
strptime
(
str_time
.
split
(
'.'
)[
0
],
'%Y-%m-%d %H:%M:%S'
)
return
datetime
.
strptime
(
str_time
.
split
(
'.'
)[
0
],
'%Y-%m-%d %H:%M:%S'
)
def
rand_str
(
str_len
=
4
):
letters
=
string
.
digits
result_str
=
''
.
join
(
random
.
choice
(
letters
)
for
i
in
range
(
str_len
))
return
result_str
def
rand_time_str
(
postfix_str_len
=
4
):
return
format_compact_datetime
(
datetime
.
now
())
+
rand_str
(
postfix_str_len
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment