10 examples of 'date time format in python' in Python

Every line of 'date time format in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
15def test_http_date_python(self):
16 format_date_time(time())
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

600def _convert_to_custom_timestamp(self, dt, format):
601 if not self._need_to_handle_f_directive(format):
602 return dt.strftime(format)
603 format = self._remove_f_from_format(format)
604 return dt.strftime(format) + '%06d' % dt.microsecond
395def format_date(d, dateformat="%Y-%m-%d"):
396 """
397 Formats a python date to the format given (strftime rules)
398 """
399 if d is None: return ""
400 try:
401 return time.strftime(dateformat, d.timetuple())
402 except:
403 return ""
24def _date_handler(obj):
25 if isinstance(obj, datetime.datetime):
26 return local_time_to_online(obj)
27 elif isinstance(obj, (featureservice.FeatureService,
28 layer.FeatureLayer,
29 layer.TableLayer)):
30 return dict(obj)
31 else:
32 return obj
6def format_date(date_object):
7 """Formats the date and returns the datetime object"""
8 # date_time = date_object.split("+")
9 return datetime.strptime(str(date_object), "%Y-%m-%dT%H:%M:%S")
531def _convert_to_datetime(self, date, input_format):
532 if isinstance(date, datetime):
533 return date
534 if is_number(date):
535 return self._seconds_to_datetime(date)
536 if is_string(date):
537 return self._string_to_datetime(date, input_format)
538 raise ValueError("Unsupported input '%s'." % date)
43def FormatDate(date, format=None):
44 ms = int(date[6:-7])
45 date = datetime.datetime.fromtimestamp(ms/1000.0)
46
47 if format:
48 return datetime.datetime.strftime(date, format)
49 else:
50 return date
55def format_date(dt):
56 """Format date/datetime in ISO_8601 format string"""
57 return dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
62def date_handler(obj):
63 return obj.isoformat() if hasattr(obj, 'isoformat') else obj
17def format_datetime(str_datetime, old_format, new_format):
18 """字符串时间格式更改
19 2013-10-10 23:40:00 --> 2013/10/10 23:40:00
20 """
21 time_array = time.strptime(str_datetime, old_format)
22 new_format = time.strftime(new_format, time_array)
23 return new_format

Related snippets