6 examples of 'strftime python' in Python

Every line of 'strftime 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
43def strftime(dt: Optional[datetime]):
44 """Format datetime as string."""
45 if dt is None:
46 return None
47 return dt.strftime(timestamp_format)
254@expectedFailure
255def test_strftime(self):
256 self.assertCodeExecution("""
257 import time
258 print(time.strftime())
259 """)
49def strftime(fmt, t=None):
50 ''' A version of strftime that returns unicode strings and tries to handle dates
51 before 1900 '''
52 if not fmt:
53 return u''
54 if t is None:
55 t = time.localtime()
56 if hasattr(t, 'timetuple'):
57 t = t.timetuple()
58 early_year = t[0] < 1900
59 if early_year:
60 replacement = 1900 if t[0]%4 == 0 else 1901
61 fmt = fmt.replace('%Y', '_early year hack##')
62 t = list(t)
63 orig_year = t[0]
64 t[0] = replacement
65 ans = None
66 if iswindows:
67 if isinstance(fmt, unicode):
68 fmt = fmt.encode('mbcs')
69 ans = plugins['winutil'][0].strftime(fmt, t)
70 else:
71 ans = time.strftime(fmt, t).decode(preferred_encoding, 'replace')
72 if early_year:
73 ans = ans.replace('_early year hack##', str(orig_year))
74 return ans
58def test_strftime_3(self):
59 # cp32215
60 d = datetime.datetime(2012,2,8,4,5,6,12314)
61 self.assertEquals(d.strftime('%f'), "012314")
22def strftime(dt, template):
23 """A replacement for datetime.strftime() which does not handle dates
24 earlier than 1900 (or beyond 2048?)."""
25
26 iso = dt.isoformat()
27 return isoformat_strftime(iso, template)
485def strftime(fmt, t=None):
486 ''' A version of strftime that returns unicode strings and tries to handle dates
487 before 1900 '''
488 if not fmt:
489 return ''
490 if t is None:
491 t = time.localtime()
492 if hasattr(t, 'timetuple'):
493 t = t.timetuple()
494 early_year = t[0] < 1900
495 if early_year:
496 replacement = 1900 if t[0]%4 == 0 else 1901
497 fmt = fmt.replace('%Y', '_early year hack##')
498 t = list(t)
499 orig_year = t[0]
500 t[0] = replacement
501 t = time.struct_time(t)
502 ans = None
503 if iswindows:
504 if isinstance(fmt, bytes):
505 fmt = fmt.decode('mbcs', 'replace')
506 fmt = fmt.replace('%e', '%#d')
507 ans = plugins['winutil'][0].strftime(fmt, t)
508 else:
509 ans = time.strftime(fmt, t)
510 if isinstance(ans, bytes):
511 ans = ans.decode(preferred_encoding, 'replace')
512 if early_year:
513 ans = ans.replace('_early year hack##', unicode_type(orig_year))
514 return ans

Related snippets