strftime

PHP date and setlocale do not always work

南笙酒味 提交于 2019-12-04 05:16:23
问题 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? 回答1: It appears that both Apache and Nginx webservers need to be

python操作日期和时间的方法

拟墨画扇 提交于 2019-12-04 02:21:25
经常获得了一个用户提交的当前日期,我们需要以这个日期为依据返回它的前一天、后一天的日期或者转换操作等。用Python可以非常简单的解决这些关于日期计算的问题 。 不管何时何地,只要我们编程时遇到了跟时间有关的问题,都要想到 datetime 和 time 标准库模块,今天我们就用它内部的方法,详解python操作日期和时间的方法。 1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" #将其转换为时间数组 import time timeArray = time.strptime(a, "%Y-%m-%d %H:%M:%S") #转换为时间戳: timeStamp = int(time.mktime(timeArray)) timeStamp == 1381419600 2.格式更改 如a = "2013-10-10 23:40:00",想改为 a = "2013/10/ 10 23:40:00" 方法:先转换为时间数组,然后转换为其他格式 timeArray = time.strptime(a, "%Y-%m-%d %H:%M:%S") otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", timeArray) 3.时间戳转换为指定格式日期 方法一:利用localtime()转换为时间数组

python抓取cacti的流量图

不想你离开。 提交于 2019-12-03 11:53:50
  有一个功能需求,每天在cacti上爬取昨天一整天的流量图,并将流量图上的min、max、average流量做成表格,用邮件发出。   1、需要使用的模块 #!/usr/bin/env python #-*- coding: UTF-8 -*- import time,datetime,cookielib,requests,sys,re,urllib2,urllib,socket,csv,heapq import smtplib import mimetypes import time from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase from email import encoders from email.MIMEImage import MIMEImage default_encoding = 'utf-8' if sys.getdefaultencoding() != default_encoding: reload(sys)   2、登陆cacti的函数 def Login1(): socket.setdefaulttimeout(10) global headers

Is there any way to use a strftime-like function for dates before 1900 in Python?

痞子三分冷 提交于 2019-12-03 09:34:49
问题 I didn't realize this, but apparently Python's strftime function doesn't support dates before 1900: >>> from datetime import datetime >>> d = datetime(1899, 1, 1) >>> d.strftime('%Y-%m-%d') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: year=1899 is before 1900; the datetime strftime() methods require year >= 1900 I'm sure I could hack together something myself to do this, but I figure the strftime function is there for a reason (and there also is a reason

Group a Ruby Array of Dates by Month and Year into a Hash

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I had a Ruby Array of Date s like: 2011-01-20 2011-01-23 2011-02-01 2011-02-15 2011-03-21 What would be an easy and Ruby-esque way of creating a Hash that groups the Date elements by year and then month, like: { 2011 => { 1 => [2011-01-20, 2011-01-23], 2 => [2011-02-01, 2011-02-15], 3 => [2011-03-21], } } I can do this by iterating over everything and extracting years, months and so on, then comining them. Ruby offers so many methods and blocks for Arrays and Hashes, there must be an easier way? 回答1: require 'date' dates = [ '2011

Python datetime to string without microsecond component

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm adding UTC time strings to Bitbucket API responses that currently only contain Amsterdam (!) time strings. For consistency with the UTC time strings returned elsewhere, the desired format is 2011-11-03 11:07:04 (followed by +00:00 , but that's not germane). What's the best way to create such a string ( without a microsecond component) from a datetime instance with a microsecond component? >>> import datetime >>> print unicode(datetime.datetime.now()) 2011-11-03 11:13:39.278026 I'll add the best option that's occurred to me as a possible

dede时间标签

£可爱£侵袭症+ 提交于 2019-12-03 06:48:34
dedecms首页时间标签: 1、12-27 样式 ([field:pubdate function='strftime("%m-%d",@me)'/]) 2、May 15, 2009 样式 ([field:pubdate function='strftime("%b %d, %Y",@me)'/]) 提示:可修改后代码再运行! dedecms列表页时间标签: 1、2009-12-27 18:30:02 样式 [field:pubdate function="GetDateTimeMK(@me)"/] 2、2009-12-27 样式 [field:pubdate function="GetDateMK(@me)"/] dedecms内容页时间标签: 1、2009-12-27 样式 {dede:field name='pubdate' function='GetDateMk(@me)'/} 2、May 15, 2009 样式 {dede:field name='pubdate' function='strftime("%b %d, %Y",@me)'/} 24小时内的时间显示红色: [field:pubdate runphp='yes'] $a="";"; $b=" $c=strftime("%Y年%m月%d日 %H:%M:%S","@me"); $ntime = time();

Ruby strftime: Month without leading zero?

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does Ruby's strftime have a format for the month without a leading zero? I found %e for getting the day without the leading zero, but not having any luck with the month. Ultimately wanting a date formatted like: 9/1/2010 回答1: Some versions of strftime do allow prefixing with minus to format out leading zeros, for eg: strftime "%-d/%-m/%y" However this will depend on strftime on your system. So for consistency I would do something like this instead: dt = Time.local(2010, 'Sep', 1) printf "%d/%d/%d", dt.day, dt.month, dt.year 回答2: Here's the

Quickly getting to YYYY-mm-dd HH:MM:SS in Perl

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When writing Perl scripts I frequently find the need to obtain the current time represented as a string formatted as YYYY-mm-dd HH:MM:SS (say 2009-11-29 14:28:29 ). In doing this I find myself taking this quite cumbersome path: man perlfunc /localtime to search for localtime - repeat five times ( / + \n ) to reach the relevant section of the manpage Copy the string ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); from the manpage to my script. Try with my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $mon,

Error parsing datetime string “09-11-2017 00:02:00” at position 8

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I created a data frame with a column of datetime objects, re sampled it but would now like to turn the data frame into a list of lists - where the datetimes are now strings again. for i in range(1, len(dataf.index)): dataf["Time Stamp"][i] = datetime.strftime(dataf["Time Stamp"][i], '%m-%d-%Y %H:%M:%S') print(dataf["Time Stamp"][i]) I keep getting the error (note the print part is just for me to check the output) ValueError: Error parsing datetime string "09-11-2017 00:02:00" at position 8 But from what I can tell my date format is exactly