time

Display a countdown for the python sleep function

萝らか妹 提交于 2020-01-10 10:15:01
问题 I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program? >>>run_my_program() tasks done, now sleeping for 10 seconds and then I want it to do 10,9,8,7.... is this possible? 回答1: you could always do #do some stuff print 'tasks done, now sleeping for 10 seconds' for i in xrange(10,0,-1): time.sleep(1) print i This snippet has the slightly annoying feature that each number gets printed out on a newline. To avoid this, you can import sys import time

Display a countdown for the python sleep function

喜你入骨 提交于 2020-01-10 10:14:41
问题 I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program? >>>run_my_program() tasks done, now sleeping for 10 seconds and then I want it to do 10,9,8,7.... is this possible? 回答1: you could always do #do some stuff print 'tasks done, now sleeping for 10 seconds' for i in xrange(10,0,-1): time.sleep(1) print i This snippet has the slightly annoying feature that each number gets printed out on a newline. To avoid this, you can import sys import time

Does Python's time.time() return a timestamp in UTC? [duplicate]

人盡茶涼 提交于 2020-01-10 08:52:10
问题 This question already has answers here : Does Python's time.time() return the local or UTC timestamp? (7 answers) Closed 3 years ago . I need to generate a UNIX timestamp in UTC time so I'm using time.time() to produce it. Do I need to do anything else or is the timestamp automatically in UTC? 回答1: Technically, time.time() doesn't specify, and practically, at least in CPython, it returns a timestamp in whatever format is used by the underlying standard C library's time function. The C

Rounding time in Python

情到浓时终转凉″ 提交于 2020-01-10 07:49:10
问题 What would be an elegant, efficient and Pythonic way to perform a h/m/s rounding operation on time related types in Python with control over the rounding resolution? My guess is that it would require a time modulo operation. Illustrative examples: 20:11:13 % (10 seconds) => (3 seconds) 20:11:13 % (10 minutes) => (1 minutes and 13 seconds) Relevant time related types I can think of: datetime.datetime \ datetime.time struct_time 回答1: For a datetime.datetime rounding, see this function: https:/

PHP strtotime problems with minutes [closed]

杀马特。学长 韩版系。学妹 提交于 2020-01-10 05:43:07
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Is that normal that this line: echo date("Y-m-d h:m:s a", strtotime('2012-03-18 12:55:00')) gives me 2012-03-18 12:03:00 pm Whatever the minutes I enter,

add two or more time strings in php

三世轮回 提交于 2020-01-10 05:42:27
问题 I have an array with times (string) e.g "2:23", "3:2:22" etc. $times = array("2:33", "4:2:22", "3:22") //loner I want to find the total sum of all array. Is there a way that I could add times like "2:33" and "3:33" ("i:s") thanks 回答1: There is no builtin way of doing this - all time functions operate on times, not on durations. In your case, you can explode() and add the parts separately. I would recommend writing a class. Simple example: class Duration { public static function fromString(

python parsing a datetime with a timezone [duplicate]

梦想与她 提交于 2020-01-10 04:40:07
问题 This question already has answers here : Python time to age, part 2: timezones [duplicate] (5 answers) Closed 4 years ago . I am trying to parse an string from a log file in the format: 2011-06-27 10:29:56+0200 If I use datetime.datetime.strptime('%Y-%m-%d %H:%M:%S%z') I get ValueError("'z' is a bad directive in format '%Y-%m-%d %H:%M:%S%z'") thrown How can I parse a date in this format? 回答1: Try using dateutil. from dateutil.parser import parse dt = parse("2011-06-27 10:29:56+0200") 来源:

Java format hour and min

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 04:28:11
问题 I need to format my time string such as this: int time = 160; Here's my sample code: public static String formatDuration(String minute) { String formattedMinute = null; SimpleDateFormat sdf = new SimpleDateFormat("mm"); try { Date dt = sdf.parse(minute); sdf = new SimpleDateFormat("HH mm"); formattedMinute = sdf.format(dt); } catch (ParseException e) { e.printStackTrace(); } return formattedMinute; // int minutes = 120; // int h = minutes / 60 + Integer.parseInt(minute); // int m = minutes %

Convert army time to regular time AM PM in PHP [closed]

安稳与你 提交于 2020-01-10 04:07:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I'm looking for a way to convert army time (such as 23:00) to regular time with the AM/PM expression. 回答1: Just pass your time in strtotime function like this: $time_in_12_hour_format = date("g:i a", strtotime(

How to get current UK time in Google App Engine

為{幸葍}努か 提交于 2020-01-10 04:05:47
问题 Under python on my machine I can run datetime.now() to get the local time. If I inspect time.daylight flag it is set to 1 because we are currently in July (hence daylight saving). But if I run datetime.now() on Google App Engine (including the dev server) it doesn't account for daylight saving (british summer time) and returns the wrong time (13:47 instead of 14:47). If I inspect time.daylight in GAE it is set to 0 . How can I get the correct local time? Do I need to change the timezone on my