strftime

Convert string to time with python [duplicate]

筅森魡賤 提交于 2019-12-10 23:54:49
问题 This question already has answers here : Parsing date/time string with timezone abbreviated name in Python? (5 answers) Closed 6 years ago . I have read a few stackoverflow posts but still can't figure this out... I want to crawl craigslist post posted within last 48 hours. Posted time is in the following format for craigslist: 2013-03-15, 7:43PM MDT I have tried string = "2013-03-15, 7:43PM MDT" time.strptime(string, "%Y-%m-%d, %I:%M%p %Z") But apparent the format doesnt match the string.

SQlite Time Difference using function strftime and date and using trigger to update on insert

倖福魔咒の 提交于 2019-12-10 18:12:22
问题 I want to have the difference between two timestamps, like Endtime = strftime('%Y-%m-%d %H:%M:%S','now','localtime') firsttime = strftime('%Y-%m-%d %H:%M:%S','2012-01-27 02:34:56') i.e. if my firsttime is 2012-06-15 14:54:33 and Endtime is 2012-06-15 14:54:40 then time diff would be like this =00:00:14; I want to have such difference between timestamps, like Endtime-firsttime I also want to use trigger to do use in SQLite database in Android. In SQL we can do it by means of converting using

ValueError parsing time string

淺唱寂寞╮ 提交于 2019-12-10 16:37:34
问题 I have written this code to convert a unusual time into EPOCH: x = 'Mon Jul 25 19:04:30 GMT+01:00 2016' print(datetime.strptime(x, '%a %b %d %H:%M:%S %Z%z %Y').strftime('%s')) However, it returns the error ValueError: time data 'Mon Jul 25 19:04:30 GMT+01:00 2016' does not match format '%a %b %d %H:%M:%S %Z%z %Y' The problem is something to do with the timezone. What have I done wrong? 回答1: Your timezone format has an extra : inside which causes the format mismatching error, you can remove

Strftime with German Date

僤鯓⒐⒋嵵緔 提交于 2019-12-10 16:01:43
问题 im trying to print the date in german with strftime. I already tried date_default_timezone_set('Europe/Berlin'); setlocale(LC_ALL, "de_DE", "de_DE@euro", "deu", "deu_deu", "german"); $time = strftime("%B", 1323956220); echo $time; //I want to see "Dezember", but I see "December" instead but it didnt work. Am I missing something? Edit: sorry I missed the strftime funciton :P 回答1: My guess: the locale is actually called de_DE.utf8 on your machine (it is on mine). Does this work for you?

python 日期封装

巧了我就是萌 提交于 2019-12-08 17:49:28
import time import datetime import locale class TimeUtil: def __init__(self, curtime=None): self.curtime = curtime def get_timestemp(self):     """时间戳""" return time.time() def get_date(self):     """日期""" return time.strftime("%Y-%m-%d") def get_time(self):     """时间""" return time.strftime("%H:%M:%S") def get_datetime(self):     """日期和时间""" return time.strftime("%Y-%m-%d %H:%M:%S") def get_chinesedate(self): strTime = time.strftime("%Y年%m月%d日", time.localtime()) return strTime def get_chinesetime(self): strTime = time.strftime("%H时%M分%S秒", time.localtime()) return strTime def get

Using strftime function in mawk

喜欢而已 提交于 2019-12-08 17:11:45
问题 I'm trying to create AWK script that will filter the input file according to some pattern, and use the strftime() function for some calculations. ($2 ~ /^[HB]/ && $2 ~ /n$/){ print strftime("%Y") } The interpreter in use is mawk. When triggering this script using this command: awk -f script3 inputFile I'm getting the error: "function strftime never defined" 回答1: Installing GAWK will get you the function strftime back that you are missing natively in awk. With Ubuntu 11.10 or simiar

Converting date formats python - Unusual date formats - Extract %Y%M%D

戏子无情 提交于 2019-12-07 22:17:45
问题 I have a large data set with a variety of Date information in the following formats: DAYS since Jan 1, 1900 - ex: 41213 - I believe these are from Excel http://www.kirix.com/stratablog/jd-edwards-date-conversions-cyyddd YYDayofyear - ex 2012265 I am familiar with python's time module, strptime() method, and strftime () method. However, I am not sure what these date formats above are called on if there is a python module I can use to convert these unusual date formats. Any idea how to get the

Python日期时间函数

强颜欢笑 提交于 2019-12-07 18:11:29
所有日期、时间的api都在datetime模块内。 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.now() now.strftime('%Y-%m-%d %H:%M:%S') 输出 '2015-04-07 19:11:21' strftime是datetime类的实例方法。 2. 日期输出格式化 string => datetime import datetime t_str = '2015-04-07 19:11:21' d = datetime.datetime.strptime(t_str, '%Y-%m-%d %H:%M:%S') strptime是datetime类的静态方法。 3. 日期比较操作 在datetime模块中有timedelta类,这个类的对象用于表示一个时间间隔,比如两个日期或者时间的差别。 构造方法: import datetime datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) 所有的参数都有默认值0,这些参数可以是int或float,正的或负的。 可以通过 timedelta.days、tiemdelta

SQLite return wrong week number for 2013?

左心房为你撑大大i 提交于 2019-12-07 00:55:38
问题 I have a simple SQL for calculating week number in my reports on SQLite SELECT STRFTIME('%W', 'date_column') It was correct for 2009-2012. In 2013 I got always the wrong week number. For example SELECT STRFTIME('%W', '2012-02-28') return '09' and this is correct. SELECT STRFTIME('%W', '2013-02-28') return '08' and this is wrong. We have the 9th week. Is there something in SQLite date time functions that I don't understand? Or is it a bug of SQLite? 回答1: CL's answer works fine for OP's

2019-05-20转换 2019年-05月-20日

旧街凉风 提交于 2019-12-06 19:07:44
# 2019-05-25 11:20:34 updatetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') import datetime import time today=datetime.date.today() oneday=datetime.timedelta(days=1) yesterday=today-oneday print(yesterday) # 2019-05-20 print(time.strftime('%Y{y}-%m{m}-%d{d}').format(y='年', m='月', d='日')) # 2019年-05月-21日 print((datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y{y}-%m{m}-%d{d}').format(y='年', m='月', d='日')) # 2019年-05月-20日 # -------- t = '2019-05-21 15:16:01' timeArray = time.strptime(t,"%Y-%m-%d %H:%M:%S") timeStamp = int(time.mktime(timeArray)) print(timeStamp) #