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
Hide whitespace changes
Inline
Side-by-side
csst_dfs_commons/convert/date_utils.py
View file @
9e7442ff
from
datetime
import
datetime
import
time
import
random
import
string
def
format_datetime
(
dt
):
return
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
...
...
@@ -20,4 +22,12 @@ def format_time_ms(float_time):
return
"%s.%03d"
%
(
data_head
,
data_secs
)
def
str_to_datetime
(
str_time
):
return
datetime
.
strptime
(
str_time
.
split
(
'.'
)[
0
],
'%Y-%m-%d %H:%M:%S'
)
\ No newline at end of file
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