Skip to content

Tag: datetime

DateTimeFormatter – Strict vs Lenient unexpected behaviour

I have some text that is only being parsed by a DateTimeFormatter when the parse style is Strict – and not when it’s Lenient. This seems like the opposite behaviour to what I’d expect? Example: Output: Answer Having posted this as a bug – I got the following reply: According to DateTimeFormatterBuilder’s spec, appendPattern(“yy”) translates to appendValueReduced(ChronoField.YEAR_OF_ERA, 2, 2000),

Convert Long to DateTime from C# Date to Java Date

I’ve been trying to read the binary file with Java, and the binary file is written in C#. And some of those data is contain a DateTime data. When DateTime data will be written into the file (in binary), it using DateTime.ToBinary(); on C#. For reading the DateTime data, it will convert first from bytes into long data, using BitConverter.ToInt64(byte[],

Issue Converting seconds to HH:MM:SS java

I have a long variable which represents the downtime of an application in seconds. I want to display the downtime as HH:mm:ss When passing the long variable to the Date I multiplied it 1000 to get the millisecond value. The newD variable evaluates to Thu Jan 01 01:12:35 GMT 1970 The value of newD is off by 1 hour, 755

How to sort a list of months with years

I have a list of months with years such as: [12-2014,11-2012,5-2014,8-2012] and I have to sort them with the most recent on top (or the latest date on top) eg. [12-2014,5-2014,11-2012,8-2012] . Does anybody have any idea on how to do this in Java efficiently? EDIT: The class YearMonth is not available, I’m on Java 7 Answer Since you are

Add interval to a datetime

I want to achieve a similar operation in java: What’s the best approach to express this in Java given the following constraints: The datetime is a formated string. The interval is an integer. The calculated time should be also a datetime formatted string. Answer You should work with “Date” objects, which basically represent an instance in time (number of milliseconds

Convert java.util.Date to java.time.LocalDate

What is the best way to convert a java.util.Date object to the new JDK 8/JSR-310 java.time.LocalDate? Answer Short answer Explanation Despite its name, java.util.Date represents an instant on the time-line, not a “date”. The actual data stored within the object is a long count of milliseconds since 1970-01-01T00:00Z (midnight at the start of 1970 GMT/UTC). The equivalent class to java.util.Date