epoch

How to convert timestamp string to epoch time?

余生长醉 提交于 2019-12-01 20:30:56
问题 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

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

≡放荡痞女 提交于 2019-12-01 19:41:47
This question already has an answer here: Java - Subtract Days from date [duplicate] 6 answers 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 * 60)); //48 comes from UI public long currentMillis(){ return new Date().getTime(); } d = new Date(timeInEpoch * 1000); I

How is a chrono::year Object Constructed?

限于喜欢 提交于 2019-12-01 19:26:21
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. In 25.8.1 [time.cal.general]: The types in 25.8 describe the civil (Gregorian) calendar and its relationship to sys_days and

Epoch is not epoch if do a new Date(0L). Why?

℡╲_俬逩灬. 提交于 2019-12-01 19:09:44
My problem is pretty straigtforward explained : if I do this : public class Main { public static void main(String[] args) throws Exception { Date d = new Date(0L ); System.out.println(d); } } I get the following output : Thu Jan 01 01:00:00 CET 1970 According to the doc, I was expecting : Thu Jan 01 00:00:00 CET 1970 I would like was going wrong... EDIT : Indeed, I read the doc too fast. I should have Thu Jan 01 00:00:00 GMT 1970 So, how can I force the use of GMT, and ignore all local time ? Edit, Solution : public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new

Epoch or iso8601 date format?

一笑奈何 提交于 2019-12-01 11:13:47
For passing times in JSON to/from a web API, why would I choose to use an ISO8601 string instead of simply the UTC epoch value? For example, both of these are the same: Epoch = 1511324473 iso8601 = 2017-11-22T04:21:13Z The epoch value is obviously shorter in length, which is always good for mobile data usage, and it's pretty simple to convert between epoch values and the language's local Date type variable. I'm just not seeing the benefit to using an ISO string value. Both are unambiguous and easy to parse in programs. The benefit of epoch like you have mentioned is that it is smaller and will

Datetime to epoch conversion

被刻印的时光 ゝ 提交于 2019-12-01 09:11:31
I have a bash question (when using awk). I'm extracting every single instance of the first and fifth column in a textfile and piping it to a new file with the following code, cut -f4 test170201.rawtxt | awk '/stream_0/ { print $1, $5 }' > testLogFile.txt This is part of the file (test170201.rawtxt) I'm extracting the data from, columns Timestamp and Loss , Timestamp Stream Status Seq Loss Bytes Delay 17/02/01.10:58:25.212577 stream_0 OK 80281 0 1000 38473 17/02/01.10:58:25.213401 stream_0 OK 80282 0 1000 38472 17/02/01.10:58:25.215560 stream_0 OK 80283 0 1000 38473 17/02/01.10:58:25.216645

Epoch or iso8601 date format?

我只是一个虾纸丫 提交于 2019-12-01 06:29:21
问题 For passing times in JSON to/from a web API, why would I choose to use an ISO8601 string instead of simply the UTC epoch value? For example, both of these are the same: Epoch = 1511324473 iso8601 = 2017-11-22T04:21:13Z The epoch value is obviously shorter in length, which is always good for mobile data usage, and it's pretty simple to convert between epoch values and the language's local Date type variable. I'm just not seeing the benefit to using an ISO string value. 回答1: Both are

Printing Time since Epoch in Nanoseconds

强颜欢笑 提交于 2019-12-01 04:45:52
问题 So I know how to print time since epoch in seconds, and evidently even milliseconds, but when I try nanoseconds I keep getting bogus output of an integer that's way too small, and it sometimes prints numbers smaller than the last run. #include <stdio.h> #include <time.h> int main (void) { long int ns; struct timespec spec; clock_gettime(CLOCK_REALTIME, &spec); ns = spec.tv_nsec;; printf("Current time: %ld nonoseconds since the Epoch\n", ns); return 0; } For instance, with a run from this I

Convert Epoch to DateTime SQL Server (Exceeds Year 2038)

一笑奈何 提交于 2019-12-01 00:58:28
How to convert Epoch to DateTime SQL Server if epoch exceeds the year 2038? Answer in Convert Epoch to DateTime SQL Server will not work. Example: SELECT DATEADD(ss, 2713795200000 / 1000, '19700101') Thu, 30 Dec 2055 16:00:00 GMT DATEADD function assumes an INT as an increment to your date, to bypass the limitation of INT you can either reduce the precision of your epoch, or do a slightly complex code to retain the precision of your epoch. This reduces the precision to minutes: SELECT DATEADD(MINUTE,@YourEpoch/60/1000, '1/1/1970') This one splits your epoch to days and milliseconds and then

Time issues

自闭症网瘾萝莉.ら 提交于 2019-12-01 00:57:47
I am facing some problems in a cross platform program : when I open a python shell in Linux and in Windows, I don't get the same time from the Epoch. In Linux, I tried to do dpkg-reconfigure tzdata . Currently, in linux I get that avec the dpkg-reconfigure tzdata : Current default time zone: 'Europe/London' Local time is now: Mon May 30 10:29:52 BST 2011. Universal Time is now: Mon May 30 09:29:52 UTC 2011. Then, in the python console, I create this script : import time print time.tzname, time.timezone, time.altzone, time.daylight print time.localtime() print time.localtime(0) On linux that