Every line of 'python datetime strftime' 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.
43 def strftime(dt: Optional[datetime]): 44 """Format datetime as string.""" 45 if dt is None: 46 return None 47 return dt.strftime(timestamp_format)
58 def test_strftime_3(self): 59 # cp32215 60 d = datetime.datetime(2012,2,8,4,5,6,12314) 61 self.assertEquals(d.strftime('%f'), "012314")
254 @expectedFailure 255 def test_strftime(self): 256 self.assertCodeExecution(""" 257 import time 258 print(time.strftime()) 259 """)
22 def 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)
49 def 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
517 def utc_strftime(self, pattern): 518 if self.value is NaN: 519 return 'Invalid Date' 520 try: 521 dt = self.to_utc_dt() 522 except: 523 raise MakeError('TypeError', 'unsupported date range. Will fix in future versions') 524 try: 525 return dt.strftime(pattern) 526 except: 527 raise MakeError('TypeError', 'Could not generate date string from this date (limitations of python.datetime)')
126 def test_strftime(): 127 d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz="local") 128 assert d.strftime("%d") == "25"
485 def 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
74 def formatDate(obj): 75 return obj.strftime("%Y%m%d%H%M00 +0800")
26 def datetime_strftime(): 27 DATETIME_OBJ.strftime(DATE_TIME_FORMAT)