collect more date formatting and parsing utilities in one central place
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3731 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									36b964fc8e
								
							
						
					
					
						commit
						31a2195958
					
				
					 1 changed files with 18 additions and 2 deletions
				
			
		
							
								
								
									
										20
									
								
								util/date.py
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								util/date.py
									
										
									
									
									
								
							|  | @ -25,13 +25,29 @@ $Id$ | ||||||
| import time | import time | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def getTimeStamp(): | ||||||
|  |     return int(time.time()) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def timeStamp2ISO(ts, useGM=False, format='%Y-%m-%d %H:%M'): | def timeStamp2ISO(ts, useGM=False, format='%Y-%m-%d %H:%M'): | ||||||
|  |     return formatTimeStamp(ts, useGM, format) | ||||||
|  | 
 | ||||||
|  | def formatTimeStamp(ts, useGM=False, format='%Y-%m-%d %H:%M'): | ||||||
|  |     if ts is None: | ||||||
|  |         ts = getTimeStamp() | ||||||
|     fct = useGM and time.gmtime or time.localtime |     fct = useGM and time.gmtime or time.localtime | ||||||
|     return time.strftime(format, fct(ts)) |     return time.strftime(format, fct(ts)) | ||||||
|     #return time.strftime('%Y-%m-%d %H:%M', time.gmtime(ts)) |     #return time.strftime('%Y-%m-%d %H:%M', time.gmtime(ts)) | ||||||
|     #return time.strftime('%Y-%m-%d %H:%M', time.localtime(ts)) |     #return time.strftime('%Y-%m-%d %H:%M', time.localtime(ts)) | ||||||
| 
 | 
 | ||||||
| def getTimeStamp(): |  | ||||||
|     return int(time.time()) |  | ||||||
| 
 | 
 | ||||||
|  | def str2timeStamp(s): | ||||||
|  |     try: | ||||||
|  |         t = time.strptime(s, '%Y-%m-%d %H:%M:%S') | ||||||
|  |     except ValueError: | ||||||
|  |         try: | ||||||
|  |             t = time.strptime(s, '%Y-%m-%d %H:%M') | ||||||
|  |         except ValueError: | ||||||
|  |             t = time.strptime(s, '%Y-%m-%d') | ||||||
|  |     return int(time.mktime(t)) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm