villabeijing.blogg.se

Java time converter
Java time converter






java time converter
  1. #Java time converter code
  2. #Java time converter iso

Regarding to the flow chart this code converts from Epoch => #6 => to Java Time => #11 => to String.

#Java time converter iso

String must be ISO 8601 formatted like this: “yyyy-MM-dd’T’HH:mm:ss.SSSZ” val Number MyEpochFromString = new DateTime(MyDateTimeString).millis #8 Get Epoch from DateTimeType val Number MyEpochFromDateTimeTypeItem = (MyDateTimeTypeItem.state as DateTimeType).

java time converter

Val MyEpochTimestamp_VariantB = now.toEpochSecond * 1000 Timestamp val MyEpochTimestamp_VariantA = Variant B val MyEpochFromJavaTime_VariantB = MyJavaTime.toEpochSecond * 1000 Variant A val MyEpochFromJavaTime_VariantA = Val MyJavaTimeFromEpoch_VariantA = Instant.ofEpochMilli(MyMilliseconds).atZone(ZoneId.systemDefault()) // #6 Variant A val long MyMilliseconds = 999999000 // create a value we can work with` String must be ISO 8601 formatted like this: “yyyy-MM-dd’T’HH:mm:ss.SSSZ” val MyZonedDateTimeFromString = ZonedDateTime.parse("T00:00:00.000Z").withZoneSameInstant(ZoneId.systemDefault()) More info about Java ZonedDateTime Class #5 Get Java Time from String #4 Get Java Time from DateTimeType val MyJavaTimeFromDateTimeItem = (MyDateTimeItem.state as DateTimeType).getZonedDateTime() Timestamp (DateTimeType) val DateTimeType MyDateTimeTypeTimestamp = DateTimeType.valueOf(now.toLocalDateTime().toString()) Regarding to the flow chart this code converts JavaTime => #11 => to String => #1 => to DateTimeType val DateTimeType MyDateTimeTypeFromJavaTime = DateTimeType.valueOf(MyJavaTime.toLocalDateTime().toString()) Val DateTimeType MyDateTimeTypeFromJavaLocalDateTime = new DateTimeType(MyJavaLocalDateTime ) // conversionīecause JavaTime and DateTimeType both accept ISO 8601 formatted date/time strings it is easy to convert from one to the other using their toString. Variant A (from LocalDateTime) val LocalDateTime MyJavaLocalDateTime = new LocalDateTime() // create a LocalDateTime value to work with` Val MyDateTimeTypeFromJavaTime = new DateTimeType(MyJavaTimeFromEpoch) // #3 convert JavaTime to DateTimeType Val MyJavaTimeFromEpoch = Instant.ofEpochMilli(MyEpochMilliseconds).atZone(ZoneId.systemDefault()) // #6 convert epoch to JavaTime

java time converter

Since no direct conversion is known, this code uses conversion #6 (Epoch to JavaTime) and then #3 (JavaTime to DateTimeType) val long MyEpochMilliseconds = 999999000 // create a epoch value to work with` String must be ISO 8601 formatted like this: “yyyy-MM-dd’T’HH:mm:ss.SSSZ” val DateTimeType MyDateTimeTypeFromString = DateTimeType.valueOf(MyString) Grafik 1082×767 54.5 KB #1 Get DateTimeType from String The numbers of the flow chart refer to the numbers of the following list. This flow chart is intended to help you finding the code needed for conversion. In certain cases it is needed to convert date/time values to a human readable. With epoc, one can compare two dates together, convert a Joda DateTime to a DateTimeType and visa versa. Epoc is the number of milliseconds that has passed since 1 January 1970 GMT and stored in a long. The lowest common denominator when working with time is to get at the epoc value. Principle java date-time concepts are LocalDateTime (date and time without any offset or time-zone) and ZonedDateTime (“full” date-time with time-zone and resolved offset from UTC/Greenwich). In openHab 3.x there are different ways to handle Date/Time values.īy default openHAB 3.x Rules DSL use java.time API to represent date and time. Because openHAB 2.x rules use Jodatime instead of Java Time API, there is still the old DateTime Conversion thread for openHAB 2.x.








Java time converter