strftime

python time.strftime %z is always zero instead of timezone offset

℡╲_俬逩灬. 提交于 2019-12-12 09:56:25
问题 >>> import time >>> t=1440935442 >>> time.strftime("%Y/%m/%d-%H:%M:%S %z",time.gmtime(t)) '2015/08/30-11:50:42 +0000' >>> time.strftime("%Y/%m/%d-%H:%M:%S %z",time.localtime(t)) '2015/08/30-13:50:42 +0000' The offset stays the same +0000, but I expect '2015/08/30-13:50:42 +0200' The timezone is correct, as the command is interpreting capital %Z as it should >>> time.strftime("%Y/%m/%d-%H:%M:%S %Z",time.localtime(t)) '2015/08/30-13:50:42 CEST' Unix date works like I want $ date -u --date

Where to hold common strftime strings like (“%d/%m/%Y”)

99封情书 提交于 2019-12-12 09:37:45
问题 In my app I find myself using stftime a lot, and mostly with 2 strings formats - ("%d/%m/%Y") and ("%H:%M") Instead of writing the string each time, I want to store those strings in some global var or something, so I can define the format strings in just one place in my app. What is the pythonic way of doing that? Should I use a global dict, a class, a function, or maybe something else? Maybe like this? class TimeFormats(): def __init__(self): self.date = "%d/%m/%Y" self.time = "%H:%M" Or

How can I Format Width in puttime?

主宰稳场 提交于 2019-12-12 04:31:05
问题 Let's say that I want to print something simple like this table: January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 I'd like to accomplish this like: for(tm i{ 0, 0, 0, 1, 0 }; i.tm_mon < 12; ++i.tm_mon) cout << put_time(&i, "%-9B") << i.tm_mon + 1 << endl; Unfortunately puttime doesn't seem to allow me to use field flags in it's format fields. Additionally this puttime doesn't seem to play nice with setw . Is my only option to do

“AttributeError: 'matrix' object has no attribute 'strftime'” error in numpy python

空扰寡人 提交于 2019-12-12 03:24:51
问题 I have a matrix with (72000, 1) dimension. This matrix involves timestamps. I want to use "strftime" as the following; strftime("%d/%m/%y") , in order to get the output something like this: '11/03/02' . I have such a matrix: M = np.matrix([timestamps]) And I have used "strftime" in order to convert all the matrix involving timestamps to a matrix involving dates in string types. For this reason, I have used "strftime" as the follwing: M = M.strftime("%d/%m/%y") When I run the code, I get this

Ruby strftime '%-m' not working in query

人盡茶涼 提交于 2019-12-12 01:22:20
问题 My goal is to query Items by their user_id, year created, and month created. I am using sqlite3 in development and postresql in production on Heroku. I want to do something like this: items.where("user_id = '?' AND strftime('%Y', created_at) = '?' AND strftime('%-m', created_at) = '?' ", 6, 2015, 3) But it returns no records. This works: items.where("user_id = '?' AND strftime('%Y', created_at) = '?' ", 6, 2015) But this returns no records: items.where("user_id = '?' AND strftime('%-m',

.mktime and .strftime help returning wrong day of week

╄→гoц情女王★ 提交于 2019-12-12 01:03:39
问题 Before I get yelled at I am not a php coder and I have searched vary heavily to try and figure this out without luck here and on the net. I have seen some things, but just don't have enough understanding to apply with my limited understanding. The php code was developed by someone who has vanished, so not supporting and I have one little bug I need to try and clean up and why a html/css guy is even trying to figure this out without much luck. So appreciate groups help and patience as well as

convert a string in to time format in c

落爺英雄遲暮 提交于 2019-12-11 18:36:41
问题 suppose I have a string "2011-08-21 21:48:45 +1200",and another one with the same format, I want to compare these 2 strings to find out which one is the early one or later one, is there a easy way to convert a string to time format rather than compare them by characters? Thanks 回答1: use getdate or strptime(). 来源: https://stackoverflow.com/questions/7524543/convert-a-string-in-to-time-format-in-c

Python timer script doesn't run when set to long periods later

孤人 提交于 2019-12-11 04:18:53
问题 What I'm trying to do is execute a script at a certain time, and for the most part it does work when I run it a short time frame from execution, say around 10 - 15 minutes. So I would run the timer script and 10 - 15 minutes later it executes it's command. Here is the code I'm using: import time import myscript from sys import exit while 1: if time.strftime("%H") == "7" and time.strftime("%M") == "15": myscript.main() exit() What I want is for the script to execute everyday in the morning.

Why does strftime('%G', strtotime('2017-01-01')) produce 2016?

北城余情 提交于 2019-12-11 04:01:52
问题 I found a possible bug in PHP 5.6. The function strftime with a parameter of %G generates the 4 digit year. However, it seems to return the wrong year when fed 1483246800 - i.e. Jan 1, 2017. It returns 2016 instead! Example code snippet: echo strftime('%G', strtotime('2017-01-01')); This should print "2017", but I get "2016" instead. I am running PHP 5.6. This edge case also shows up for other years - e.g. 2016-01-03 outputs 2015 instead of 2016. 回答1: It's not a bug. As someone pointed out in

Issues with strftime in PHP

喜你入骨 提交于 2019-12-11 01:45:20
问题 I am currently using phpjobscheduler that uses strftime. The biggest issue I am having is converting setlocale for Europe/London this is the current functions.php I need help with log_date=strftime("Date: %d %b %Y Time: %H:%M:%S",$date_added); With the current settings in the code below the schedule task does not run at the given time and sometimes runs 15 - 30 mins ealier which I think is a setlocale. If someone can give an idea on how to modify the code so that it runs at Europe/London , I