Every line of 'convert string to time 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.
29 @classmethod 30 def convert_time(cls, time_str): 31 """Convert date string to datetime object 32 """ 33 if cls.date_ignore_pattern: 34 time_str = re.sub(cls.date_ignore_pattern, '', time_str) 35 return datetime.strptime(time_str, cls.date_format)
43 def convert_datetime(s): 44 """ 45 Convert a datetime string to a standard format 46 """ 47 try: 48 dt = DateTimeFromString(s) 49 date_string = dt.Format("%m/%d/%Y %H:%M:%S") 50 return date_string 51 except: 52 return s
108 def parse_time(tstring): 109 """Allow for various timestamp formats""" 110 if tstring is None or tstring == "": 111 tstring = "201308211200" 112 if tstring.find("T") > 0: 113 # Assume ISO 114 dt = datetime.datetime.strptime(tstring[:16], "%Y-%m-%dT%H:%M") 115 else: 116 dt = datetime.datetime.strptime(tstring[:12], "%Y%m%d%H%M") 117 118 return dt.replace(tzinfo=pytz.utc)
194 def str2time(t): 195 """change the string to a time dict""" 196 197 c1 = t.find(':') 198 c2 = t.rfind(':') 199 s = int(t[c2+1:]) 200 h = 0 201 if c1==c2: 202 m = int(t[:c1]) 203 else: 204 m = int(t[c1+1:c2]) 205 h = int(t[:c1]) 206 207 return {'hours':h,'minutes':m,'seconds':s}
117 def parse_time(time_string): 118 """Parse a time string from the config into a :class:`datetime.time` object.""" 119 formats = ['%I:%M %p', '%H:%M', '%H:%M:%S'] 120 for f in formats: 121 try: 122 return datetime.strptime(time_string, f).time() 123 except ValueError: 124 continue 125 raise ValueError(f'invalid time `{time_string}`')
1034 def GetTimeFromString(s): 1035 if s is None or len(s) == 0: 1036 return None 1037 fmt = [] 1038 fmt.append('%a, %d %b %Y %H:%M:%S %Z') 1039 st = None 1040 for f in fmt: 1041 try: 1042 st = time.strptime(s, f) 1043 except ValueError: 1044 continue 1045 return st
52 def time_object_to_string(time_object): 53 return datetime.strftime(time_object, '%Y-%m-%d %H:%M:%S')
140 def Str2Time(arg): 141 return _Strptime(arg, '%H:%M:%S').time()
89 def time_to_str(obj): 90 """ 91 Converts a time object to a string using OpenERP's 92 time string format (exemple: '15:12:35'). 93 """ 94 if not obj: 95 return False 96 return obj.strftime(DEFAULT_SERVER_TIME_FORMAT)
26 def to_datetime(string): 27 """Load UTC time as a string into a datetime object.""" 28 try: 29 # Format is 2011-07-05 01:26:12.084316 30 return datetime.datetime.strptime( 31 string.split('.', 1)[0], '%Y-%m-%d %H:%M:%S') 32 except ValueError: 33 return datetime.datetime.strptime(string, '%Y-%m-%d')