epoch

Convert Unix timestamp into datetime

我们两清 提交于 2019-12-03 10:41:00
问题 I have the following data frame > head(try) creates time 1 128.29508 1417392072 3 236.98361 1417392072 7 98.45902 1417392072 9 157.44068 1417392131 10 227.38333 1417392131 11 242.03390 1417392131 > str(try) 'data.frame': 102968 obs. of 2 variables: $ creates: num 128.3 237 98.5 157.4 227.4 ... $ time : Factor w/ 26418 levels "1417392071","1417392072",..: 2 2 2 3 3 3 3 3 5 5 ... I am unable to convert the UNIX timestamp into datetime using the following methods I tried > head(as.POSIXlt(as

Convert eg. 2012-05-25 to seconds since January 1 1970

北战南征 提交于 2019-12-03 07:23:29
I have a database where I save time as time() from php, which is seconds since 1 jan 1970 . Is there any way I can convert, for example 2012-12-12 to seconds since 1 jan 1970 ? I want to do like: SELECT * FROM Table WHERE date > '2012-11-30' AND date < '2012-12-30' Is this even possible? (I would like to do it without any php date()) DATEDIFF is going to be your friend here: select datediff(s, '1970-01-01', '2012-12-12') as SecondsSinceEpoch Note that because datediff returns an int, the maximum datetime you can compare (using seconds) with Jan 1st, 1970 is 2038-01-19 03:14:07 . 来源: https:/

Creating a unique timestamp in Java

▼魔方 西西 提交于 2019-12-03 06:53:19
问题 I need to create a timestamp (in milliseconds) in Java that is guaranteed to be unique in that particular VM-instance. I.e. need some way to throttle the throughput of System.currentTimeMillis() so that it returns at most one results every ms. Any ideas on how to implement that? 回答1: This will give a time as close the current time as possible without duplicates. private static final AtomicLong LAST_TIME_MS = new AtomicLong(); public static long uniqueCurrentTimeMS() { long now = System

Java 8: How to create a ZonedDateTime from an Epoch value?

ぐ巨炮叔叔 提交于 2019-12-03 06:28:16
问题 Java 8's LocalDateTime has an ofEpochSecond method. Unfortunately, there is no such method in the ZonedDateTime . Now, I have an Epoch value and an explicit ZoneId given. How do I get a ZonedDateTime out of these? 回答1: You should be able to do this via the Instant class, which can represent a moment given the epoch time. If you have epoch seconds, you might create something via something like Instant i = Instant.ofEpochSecond(t); ZonedDateTime z = ZonedDateTime.ofInstant(i, zoneId); 来源: https

Convert Unix timestamp into datetime

谁说胖子不能爱 提交于 2019-12-03 00:08:00
I have the following data frame > head(try) creates time 1 128.29508 1417392072 3 236.98361 1417392072 7 98.45902 1417392072 9 157.44068 1417392131 10 227.38333 1417392131 11 242.03390 1417392131 > str(try) 'data.frame': 102968 obs. of 2 variables: $ creates: num 128.3 237 98.5 157.4 227.4 ... $ time : Factor w/ 26418 levels "1417392071","1417392072",..: 2 2 2 3 3 3 3 3 5 5 ... I am unable to convert the UNIX timestamp into datetime using the following methods I tried > head(as.POSIXlt(as.numeric(try$time),origin="1970-01-01",tz="GMT")) [1] "1970-01-01 00:00:02 UTC" "1970-01-01 00:00:02 UTC"

Determine if a time is between two times regardless of date

时光毁灭记忆、已成空白 提交于 2019-12-02 13:05:52
I created a custom TimePicker preference for my Android Wear watch face. The user selects a time and it returns the current time in milliseconds. The code for this can be found on my GitHub repo . I don't think there is anything wrong with what I'm doing in that class--but maybe I am. Anyways, I then go to read the values like so: final long nightModeStartTimeMillis = prefs.getLong("settings_night_mode_start_time", Long.valueOf(getString(R.string.settings_night_mode_default_start_time))); final long nightModeEndTimeMillis = prefs.getLong("settings_night_mode_end_time", Long.valueOf(getString(R

How to calculate epoch day?

此生再无相见时 提交于 2019-12-02 02:28:59
问题 Is calculating the epoch day as simple as taking the epoch seconds and dividing by 86400? Or are there some special calculations that need to be done to take account of daylight savings or leap year or some other factor? Update: by "epoch day" I mean number of days since the epoch. 回答1: POSIX defines that you can deduce the number of days since The Epoch (1970-01-01 00:00:00Z) by dividing the timestamp by 86400. This deliberately and consciously ignores leap seconds. See the definition

How is a chrono::year Object Constructed?

北战南征 提交于 2019-12-01 22:09:58
问题 I just noticed that c++20 is going to have chrono::year. It's constructor takes in an int in the range: [-32767, 32767] , however I am unclear what this argument represents. Would this be consistent with tm_year's 1900 origin? Or perhaps time_t's 1970 origin? Or perhaps it's in Anno Domini with a 0 origin? EDIT: This is key to the understanding of what is meant by the is_leap function chrono::year offers. Without an origin it's unclear what year is represented here. 回答1: In 25.8.1 [time.cal

subtracting two days from current date in epoch milliseconds java [duplicate]

旧时模样 提交于 2019-12-01 21:37:04
问题 This question already has answers here : Java - Subtract Days from date [duplicate] (6 answers) Closed 4 years ago . I am trying to do something really simple. I am trying to subtract 2 days from the current day. I get the number of hours from the UI. So in this example, I get 48 hours from the UI. I am doing the following and I don't know what i'm doing wrong here. I think the result of this is it only subtracts a few minutes from the time. long timeInEpoch = (currentMillis()/1000 - (48 * 60

How to convert timestamp string to epoch time?

南楼画角 提交于 2019-12-01 21:04:11
I have time stamp in format 2017-18-08 11:45:30.345 . I want to convert it to epoch time, so I am doing below: String timeDateStr = "2017-18-08 11:45:30.345"; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-dd-MM HH:mm:ss.SSS"); ZonedDateTime zdt = ZonedDateTime.parse(timeDateStr, dtf); System.out.println(zdt.toInstant().toEpochMilli()); I am getting below error: java.time.format.DateTimeParseException: Text '2017-18-08 11:45:30.345' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor I also tried different formats but still getting errors. Note : originally the