strftime

python 时间对应计算

旧城冷巷雨未停 提交于 2019-12-02 18:18:43
import re import time def parse_time(date): if re.match('刚刚', date): date = time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())) if re.match('\d+分钟前', date): minute = re.match('(\d+)', date).group(1) date = time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time() - float(minute) * 60)) if re.match('\d+小时前', date): hour = re.match('(\d+)', date).group(1) date = time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time() - float(hour) * 60 * 60)) if re.match('昨天.*', date): date = re.match('昨天(.*)', date).group(1).strip() print(date) date = time.strftime('%Y-%m-%d', time.localtime(time

日期strftime、strptime

左心房为你撑大大i 提交于 2019-12-02 15:01:34
#time strftime(format,tuple)接收时间元组,返回表示时间的字符串。str-format-time, 时间字符串格式化,即我们看到的格式。 #time strptime(string,format)把时间字符串,解析成一个时间元组。 str-parse-time,时间字符串语法化,即计算机理解的格式。 示例: import time t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print(t) print(type(t)) q = time.strptime(t,'%Y-%m-%d %H:%M:%S')#format和t的格式要一致,都有时分秒或者都没有 print q print(type(q)) 程序输出: 2018-06-27 13:33:13 type 'str' time.struct_time(tm_year=2018, tm_mon=6, tm_mday=27, tm_hour=13, tm_min=33, tm_sec=13, tm_wday=3, tm_yday=178, tm_isdst=-1) type 'time.struct_time' 示例:自定义输入日期,返回日期相关的信息。 import time a = raw_input(

PHP strftime outputs wrong format despite correct timezone

荒凉一梦 提交于 2019-12-02 13:17:21
I configured my timezone to Europe/Paris in php.ini. When executing date_default_timezone_get() I do get the correct value. Then, I expect strftime('%x', date()) to output something like 16 novembre 2018 which is the French format. But instead, I get 11/16/2018 which looks like the US format. Any idea why? The time zone has no effect on how dates and times are presented, for that you need to set the locale. There are no standards for locale names, but fortunately PHP's setlocale() function will take multiple locale names, stopping at the first successful one. // just a few common name formats

'strftime' is not a recognized built-in function name

删除回忆录丶 提交于 2019-12-02 08:51:00
问题 I am using Microsoft SQL Database Management Studio and it will not allow me to use the strftime() function to run a query. I have to create a table by months with new users and unsubscribers for each month. This is what I had essentially which creates the error: SELECT strftime('%m', createddate) AS 'Month', COUNT(createddate) AS 'Subscribers', COUNT(dateunsubscribed) AS 'UNsubscribers' FROM subscriber GROUP BY 1 ORDER BY 1; how else could I run this query without strftime() or how can I get

strftime for Indonesia Locale

耗尽温柔 提交于 2019-12-02 06:37:56
问题 I am using strftime function of php to get time according to my set locale. So for Indonesian in case of February it is returning 'Pebruari' instead of "Februari". Suggest what to do ? 回答1: Please try this: <?php setlocale(LC_ALL, 'IND'); echo strftime("Today in Indonesia is %B"); ?> This will return you "Februari"... 回答2: It seems like Indonesian locale is not installed on the server you are working with. If you have shell access to your server then can you kindly try: locale -a And check

Unicode setlocale and strftime fails at windows

半世苍凉 提交于 2019-12-02 06:00:46
问题 I have one page and it's encoding is UTF-8 and If i try to run that code in unix system everythings looks fine but when i try to run in windows(7) some chracters looks question mark(�). How can run the code fine both of two system(without using iconv). header('Content-Type: text/html; charset=UTF-8'); setlocale(LC_ALL, 'turkish'); echo strftime("%d %B %Y, %H:%M"); 回答1: For those who is having similar problems on linux (this may work also for windows but not sure). Yes there is 'turkish' but

发布时间

懵懂的女人 提交于 2019-12-02 04:58:23
from datetime import datetime from datetime import timedelta if "刚刚" in publish_time: publish_time = datetime.now().strftime('%Y-%m-%d %H:%M') elif "分钟" in publish_time: minute = publish_time[:publish_time.find("分钟")] minute = timedelta(minutes=int(minute)) publish_time = ( datetime.now() - minute).strftime( "%Y-%m-%d %H:%M") elif "今天" in publish_time: today = datetime.now().strftime("%Y-%m-%d") time = publish_time.replace('今天','') publish_time = today + " " + time elif "月" in publish_time: year = datetime.now().strftime("%Y") publish_time = str(publish_time) print publish_time publish_time =

'strftime' is not a recognized built-in function name

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 04:36:06
I am using Microsoft SQL Database Management Studio and it will not allow me to use the strftime() function to run a query. I have to create a table by months with new users and unsubscribers for each month. This is what I had essentially which creates the error: SELECT strftime('%m', createddate) AS 'Month', COUNT(createddate) AS 'Subscribers', COUNT(dateunsubscribed) AS 'UNsubscribers' FROM subscriber GROUP BY 1 ORDER BY 1; how else could I run this query without strftime() or how can I get strftime() to work? strftime is a mysql function, and isn't available in Microsoft's sql-server . For

PHP date and setlocale do not always work

耗尽温柔 提交于 2019-12-02 04:26:27
After generating the required locale on our development server and using setlocale to provide PHP with the locale to use the dates formatted with strftime would appear fully translated, as expected. After reloading the page however, the dates were shown in the server's default locale: en_US . Reloading the pages multiple times resulted in almost a 50/50 chance of the dates being translated. Weird. What is happening here? It appears that both Apache and Nginx webservers need to be restarted after having locales generated for them to be able to use them without problems. Either use service

Outputting dates in non-ASCII characters with PHP

怎甘沉沦 提交于 2019-12-02 01:46:15
问题 I'm trying to output the date in Traditional Chinese. I have the date as a Unix timestamp, ( example: "1467244800" ). I am doing the following: <?php setlocale (LC_TIME, "zh_TW"); echo strftime("%e %B %Y", $timestamp ); ?> What I'm getting output is the Unicode "Undefined" characters: 30 ���� 2016 17 �T�� 2016 18 �Q�G�� 2015 Can anyone tell me what I'm doing wrong? My HTML headers contain: <html lang="zh-TW"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> And the rest of