strftime

DateTime::format and strftime

倾然丶 夕夏残阳落幕 提交于 2019-12-05 21:11:29
I have $date = $run['at']; which gives me 2013-06-03T16:52:24Z (from a JSON input). To transform it to get for example " d M Y, H:i " I use $date = new DateTime($run['at']); echo $date->format('d M Y, H:i'); Problem is I need the date in italian. And the only function that supports set_locale is strftime . How can I "wrap" DateTime::format with strftime (or replace, dunno)? setlocale(LC_TIME, 'it_IT.UTF-8'); $date = new DateTime($run['at']); strftime("%d %B", $date->getTimestamp()) ... worked. :) I believe the "proper" way should be using DateTimeZone 来源: https://stackoverflow.com/questions

Convert NSDate to String with strftime

岁酱吖の 提交于 2019-12-05 08:58:56
How would I convert an NSDate to a NSString, formatted with strftime specifiers? you could use strftime. NSDate *date = [NSDate date]; time_t time = [date timeIntervalSince1970]; struct tm timeStruct; localtime_r(&time, &timeStruct); char buffer[80]; strftime(buffer, 80, "%d.%m.%Y %H:%M:%S", &timeStruct); NSString *dateStr = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding]; I hope it's correct. You'll need an NSDateFormatter , using setDateFormat: . Here's the documentation . 来源: https://stackoverflow.com/questions/5008876/convert-nsdate-to-string-with-strftime

SQLite return wrong week number for 2013?

醉酒当歌 提交于 2019-12-05 05:39:52
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? CL's answer works fine for OP's definition of "right", which is not quite the same as ISO definition. ISO week numbers are always in the range 1-53

time时间模块

心不动则不痛 提交于 2019-12-05 04:27:22
time时间模块的常用方法: sleep时间延迟 1 time.sleep(5) # 程序走到这儿会等待5秒钟 时间的格式: 1 # '2018-8-20' '2018.8.20' 字符串数据类型 格式化时间 - 给人看的 2 # 结构化时间 3 # 1574275685.803445 浮点型数据类型,以s秒为单位 时间戳时间 - 给机器计算用的 4 # 1970 1 1 0:0:0 时间戳时间: print(time.time()) #结果:1574275685.803445 strftime格式化时间: 1 print(time.strftime('%Y-%m-%d %H:%M:%S')) #字符串类型时间 2 #结果:2019-11-21 02:49:25 3 print(time.strftime('%y-%m-%d %H:%M:%S')) #字符串类型时间 4 #结果:19-11-21 02:49:25 5 print(time.strftime('%c')) 6 #结果:Thu Nov 21 02:49:25 2019 localtime结构化时间: 1 struct_time = time.localtime() # 北京时间 2 print(struct_time) 3 #结果:time.struct_time(tm_year=2019, tm_mon=11, tm

常用的python内置模块

烂漫一生 提交于 2019-12-05 01:10:13
1、time模块: time模块是普通的时间模块 在python的三种时间表现形式: 1.时间戳: 给电脑看的。 - 自1970-01-01 00:00:00到当前时间,按秒计算,计算了多少秒。 2.格式化时间(Format String): 给人看的 - 返回的是时间的字符串 2002-01-11 3.格式化时间对象(struct_time): - 返回的是一个元组, 元组中有9个值: 9个值分别代表: 年、月、日、时、分、秒、一周中第几天,一年中的第几天,夏令时(了解)1)获取时间戳: import time # 获取时间戳(******)计算时间时使用 print(time.time()) #1573895872.453043 ,给电脑看的 2)格式化时间: # 获取年月日 print(time.strftime('%Y-%m-%d')) #2019-11-16 # # 获取年月日时分秒 print(time.strftime('%Y-%m-%d %H:%M:%S')) #2019-11-16 17:20:15 # # %X == %H:%M:%S print(time.strftime('%Y-%m-%d %X')) #2019-11-16 17:20:15 # 获取年月 print(time.strftime('%Y/%m')) #2019/11 3) 获取时间对象:

time时间模块

本小妞迷上赌 提交于 2019-12-05 01:06:23
常用模块之 time(时间模块) python中的三种时间表现形式: 1.时间戳:time.time() ,获取当前时间戳,返回值是一个float类型的毫秒值 2.格式化时间:time.strftime(), 接受时间元组, 并返回以可读字符串表示的当地时间 3.格式化时间对象:time.struct_time,返回<class 'time.struct_time'>,可以认为是一个9个整数的序列 常用方法 1.sleep(秒数) #线程睡眠多长秒 import time time.sleep(2) #两秒后输出打印内容 print('...') 2.time() #获取当前时间戳,返回值是一个float类型的毫秒值 import time #获取当前时间戳,自1970-01-01 00:00:00到当前时间,按秒计算 print(time.time()) #1573888376.157964 3.gmtime() #返回一个时间元组,就是伦敦时间 import time print(time.strftime('%Y-%m-%d %X', time.gmtime())) print(time.gmtime()) #结果为 2019-11-16 07:38:30 time.struct_time(tm_year=2019, tm_mon=11, tm_mday=16, tm

python内置模块(time模块)

痞子三分冷 提交于 2019-12-04 15:48:19
常用的python内置模块 一、time模块 在python的三种时间表现形式: 1、时间戳,给电脑看的。 - 自1970-01-01 00:00:00到当前时间,按秒计算,计算了多少秒。 import timeprint(time.time()) 2、格式化时间(forma string):给人看的。 - 返回的是时间的字符串 print(time.strftime('%Y-%m-%d')) # 获取年月日#2019-11-16 print(time.strftime("%Y-%m-%d %H:%M:%S")) # 获取年月日时分秒 print(time.strftime("%Y/%m")) # 获取年月3、获取时间对象返回的是一个元组,元组中有9个值:9个值分别代表:年、月、日、时、分、秒、一周中第几天,一年中的第几天,夏令时print(time.localtime()) 运行结果为:time.struct_time(tm_year=2019, tm_mon=11, tm_mday=16, tm_hour=15, tm_min=2, tm_sec=22, tm_wday=5, tm_yday=320, tm_isdst=0) print(type(time.localtime()))运行结果为:<class 'time.struct_time'>time_obj = time

strftime function in SQLite does not work

做~自己de王妃 提交于 2019-12-04 15:38:39
Hi, I am using the following query but it does not work, SELECT strftime('%m',Since) AS Month FROM Dates Type of Since column is DATETIME , but the result is shown an empty Month column without any error. strftime isn't broken, it just doesn't understand the format of the datestamps in your database. SQLite version 3.7.9 2011-11-01 00:52:41 sqlite> create table dates (id int, d datetime); sqlite> insert into dates (id,d) values (1, date('now')); sqlite> insert into dates (id,d) values (2, 'bad date'); sqlite> insert into dates (id,d) values (3, NULL); sqlite> insert into dates (id,d) values (4

PHP: strftime(), date() or DateTime, Which is better?

这一生的挚爱 提交于 2019-12-04 10:01:32
问题 I am curious to know if there is any advantage in PHP of using strftime() over date() or vice versa. A class I downloaded used the strftime() . However, since it does not support all time formats on some systems, I want to change it to use date() instead. I was wondering if there are any major differances or advantages in using one over the other. What about the fact that strftime() only supports date formats that are supported by that servers c library? Does date() have any similar

es数据二次开发统计展示

不羁岁月 提交于 2019-12-04 08:46:01
案例1 在es查询中按照多列分组的时候 分组列的count值会越来越少 es默认隐藏了没有被分组匹配到的记录数 需要在查询的时候开启 2.开启显示没有被分组成功的记录 分组成功的记录加上分组missing的记录数就等于总的记录数 26932+2666=29598 3.当实际的总数和es分组统计的条数对不上的时候 需要考虑是不是分组列的值有可能被丢失了 这个时候可以开启显示丢失 4.查看es的原始日志内容确实有10001条记录不存在CHANNEL字段 实例统计 #!/usr/bin/env python # -*- coding: utf-8 -*- from elasticsearch6 import Elasticsearch import datetime import time import re es = Elasticsearch("http://10.000.142.88:9200") #每小时定时执行统计前一个小时的数据 def formartTime(startTime): try: startTime = datetime.datetime.strptime(startTime, '%Y-%m-%dT%H:%M:%S.%f') except Exception as e: startTime = datetime.datetime.strptime