time

Set time in php to 00:00:00

送分小仙女□ 提交于 2020-01-12 07:24:06
问题 I need to display the time but it must start from 00:00:00? I've got the following but it uses the current time. print(date("H:i:s")); 回答1: As an alternative to mktime() , try the newer DateTime class, eg $dt = new DateTime; $dt->setTime(0, 0); echo $dt->format('H:i:s'); // Add one hour $dt->add(new DateInterval('PT1H')); echo $dt->format('H:i:s'); Update The flexibility of DateInterval makes this a very good candidate for a timer, eg // add 2 years, 1 day and 9 seconds $dt->add(new

How to parse days/hours/minutes/seconds in ruby?

拜拜、爱过 提交于 2020-01-12 07:11:46
问题 Is there a gem or something to parse strings like "4h 30m" "1d 4h" -- sort of like the estimates in JIRA or task planners, maybe, with internationalization? 回答1: Posting a 2nd answer, as chronic (which my original answer suggested) doesn't give you timespans but timestamps. Here's my go on a parser. class TimeParser TOKENS = { "m" => (60), "h" => (60 * 60), "d" => (60 * 60 * 24) } attr_reader :time def initialize(input) @input = input @time = 0 parse end def parse @input.scan(/(\d+)(\w)/)

Joda Time: Convert UTC to local

折月煮酒 提交于 2020-01-12 05:35:08
问题 I want to convert a Joda Time UTC DateTime object to local time. Here's a laborious way to do it which seems to work. But there must be a better way. Here's the code (in Scala) without surrounding declarations: val dtUTC = new DateTime("2010-10-28T04:00") println("dtUTC = " + dtUTC) val dtLocal = timestampLocal(dtUTC) println("local = " + dtLocal) def timestampLocal(dtUTC: DateTime): String = { // This is a laborious way to convert from UTC to local. There must be a better way. val instantUTC

How to check for new files in the directory?

走远了吗. 提交于 2020-01-12 03:53:46
问题 Given: filesystem::path toDir("./"); ptime oldTime; ptime now(second_clock::local_time()); How can I determine which files were created in the time period between oldTime and now ? The names of such "fresh" files should be streamed to cout . Update: Well based on given answer I made a small programm: #include <sstream> #include <stdio.h> #include <time.h> #include <boost/filesystem.hpp> #include <boost/thread.hpp> #include <boost/timer.hpp> #include <boost/date_time.hpp> #include <boost/date

Python - Convert epoch time with nanoseconds to human-readable? [duplicate]

前提是你 提交于 2020-01-12 03:08:27
问题 This question already has answers here : Parsing datetime strings containing nanoseconds (3 answers) Closed 6 years ago . I have a timestamp in epoch time with nanoseconds - e.g. 1360287003083988472 nanoseconds since 1970-01-01. The Python datetime objects and conversion methods only support up to millisecond precision. Is there an easy way to convert this epoch time into human-readable time? Cheers, Victor 回答1: First, convert it to a datetime object with second precision (floored, not

Convert DateInterval object to seconds in php

回眸只為那壹抹淺笑 提交于 2020-01-12 02:52:50
问题 $datetime1 = date_create('2009-10-11'); $datetime2 = date_create('2009-10-13'); $interval = date_diff($datetime1, $datetime2); How do i convert the above $interval to seconds in php 回答1: There is a function format for this. But it wont return the number of seconds. To get number of seconds you use this technique $seconds = abs($datetime1->getTimestamp()-$datetime2->getTimestamp()); If you really want to use $interval you need to calculate it. $seconds = $interval->days*86400 + $interval->h

Accurate time detection while offline

帅比萌擦擦* 提交于 2020-01-12 01:54:10
问题 Background Information I am developing an iOS application that is connected to a server, and requests can be made from the device towards the server to synchronize the local database with the server's database. Changes can occur on either one of the databases. The application also has an offline feature, where users can modify the data without being connected to an internet connection, and only going online in order to synchronize the device's local database with the server's database, by

How to understand strptime vs. strftime

浪子不回头ぞ 提交于 2020-01-11 20:12:02
问题 What's the difference between strptime and strftime ? I see that strptime is a method in the DateTime class, and strftime is a method in the Time class. What's the difference between Time and DateTime , other than that they have different core methods? The explanation for the Time class in the Ruby docs is helpful, but the one for DateTime just says "datetime". There's also the Date class, which says it provides Date and DateTime . Help me make sense of this. I see strptime and I want to

Get the first and last day of current month in Go/Golang?

℡╲_俬逩灬. 提交于 2020-01-11 20:11:16
问题 I'm trying to get the first and last day of the current month. You can add days and hours but not the month, which I was thinking of subtracting one day from the next month to get the last day of this month. Something like this: package main import ( "fmt" "time" ) func main() { date := time.Now() nextMonth := date.Add(time.Month) LastDay := nextMonth.Add(-time.Hour * 24) fmt.Println(LastDay) } 回答1: You can use now library, it really simple : now.BeginningOfMonth() // 2013-11-01 00:00:00 Fri

Get the first and last day of current month in Go/Golang?

送分小仙女□ 提交于 2020-01-11 20:11:15
问题 I'm trying to get the first and last day of the current month. You can add days and hours but not the month, which I was thinking of subtracting one day from the next month to get the last day of this month. Something like this: package main import ( "fmt" "time" ) func main() { date := time.Now() nextMonth := date.Add(time.Month) LastDay := nextMonth.Add(-time.Hour * 24) fmt.Println(LastDay) } 回答1: You can use now library, it really simple : now.BeginningOfMonth() // 2013-11-01 00:00:00 Fri