List of usage examples for java.time LocalTime of
public static LocalTime of(int hour, int minute, int second)
From source file:Main.java
public static void main(String[] args) { LocalTime l = LocalTime.of(12, 23, 34); System.out.println(l); }
From source file:Main.java
public static void main(String[] args) { LocalTime localTime = LocalTime.of(11, 20, 50); System.out.println(localTime.plus(3, ChronoUnit.HOURS)); System.out.println(localTime.plus(Duration.ofDays(3))); //11:20:50 try {// w w w. j a v a 2 s .com System.out.println(localTime.plus(Period.ofDays(3))); } catch (UnsupportedTemporalTypeException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { LocalDate ld = LocalDate.of(2014, Month.JUNE, 21); LocalTime lt = LocalTime.of(17, 30, 20); LocalDateTime ldt = LocalDateTime.of(ld, lt); DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); System.out.println("Formatter Default Locale: " + fmt.getLocale()); System.out.println("Short Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); System.out.println("Medium Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); System.out.println("Long Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL); System.out.println("Full Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); System.out.println("Short Time: " + fmt.format(lt)); fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); System.out.println("Short Datetime: " + fmt.format(ldt)); fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); System.out.println("Medium Datetime: " + fmt.format(ldt)); // Use German locale to format the datetime in medius style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.GERMAN); System.out.println(fmt.format(ldt)); // Use Indian(English) locale to format datetime in short style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(new Locale("en", "IN")); System.out.println(fmt.format(ldt)); // Use Indian(English) locale to format datetime in medium style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(new Locale("en", "IN")); System.out.println(fmt.format(ldt)); }
From source file:Main.java
public static void main(String[] args) { // current // ww w.j a va 2 s .com LocalDateTime localDateTime1 = LocalDateTime.now(); System.out.println(localDateTime1); // 2014-06-21T16:12:34 LocalDateTime localDateTime2 = LocalDateTime.of(2014, Month.JUNE, 21, 16, 12, 34); System.out.println(localDateTime2); // from a local date and a local time LocalDate localDate1 = LocalDate.of(2014, 5, 10); LocalTime localTime = LocalTime.of(16, 18, 41); LocalDateTime localDateTime3 = LocalDateTime.of(localDate1, localTime); System.out.println(localDateTime3); }
From source file:Main.java
public static void main(String[] args) { TemporalAdjuster temporalAdjuster = (Temporal t) -> t.plus(Period.ofDays(10)); System.out.println(temporalAdjuster); TemporalAdjuster fourMinutesFromNow = temporal -> temporal.plus(4, ChronoUnit.MINUTES); LocalTime localTime1 = LocalTime.of(12, 0, 0); System.out.println(localTime1.with(temporal -> temporal.plus(4, ChronoUnit.MINUTES))); System.out.println(Instant.now().with(temporalAdjuster)); LocalDate localDate1 = LocalDate.of(2013, 12, 13); System.out.println(localDate1.with(TemporalAdjusters.lastDayOfMonth())); }
From source file:metrolink.MetrolinkCalculator.java
private LocalTime convertTime(String time) { String[] values = time.split(":"); int hour = Integer.parseInt(values[0]); int minute = Integer.parseInt(values[1]); int second = 0; if (hour >= 24) { hour = hour - 24;/* w w w .j a v a 2 s .c o m*/ } return LocalTime.of(hour, minute, second); }
From source file:defaultmethods.SimpleTimeClient.java
public void setTime(int hour, int minute, int second) { LocalDate currentDate = LocalDate.from(dateAndTime); LocalTime timeToSet = LocalTime.of(hour, minute, second); dateAndTime = LocalDateTime.of(currentDate, timeToSet); }
From source file:defaultmethods.SimpleTimeClient.java
public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) { LocalDate dateToSet = LocalDate.of(day, month, year); LocalTime timeToSet = LocalTime.of(hour, minute, second); dateAndTime = LocalDateTime.of(dateToSet, timeToSet); }
From source file:fixio.netty.codec.FixMessageDecoderTest.java
@Test public void testDecode() throws Exception { List<Object> result = decode( "8=FIX.4.1\u00019=90\u000135=0\u000149=INVMGR\u000156=BRKR\u000134=240\u000152=19980604-08:03:31\u000110=129\u0001"); assertEquals(1, result.size());// www . ja va 2 s . c o m assertTrue(result.get(0) instanceof FixMessageImpl); final FixMessageImpl fixMessage = (FixMessageImpl) result.get(0); FixMessageHeader header = fixMessage.getHeader(); assertEquals("FIX.4.1", fixMessage.getHeader().getBeginString()); assertEquals(MessageTypes.HEARTBEAT, fixMessage.getMessageType()); assertEquals("INVMGR", header.getSenderCompID()); assertEquals("BRKR", header.getTargetCompID()); assertEquals(240, header.getMsgSeqNum()); assertEquals(129, fixMessage.getChecksum()); final Long value = fixMessage.getValue(FieldType.SendingTime); assertEquals(ZonedDateTime.of(LocalDate.of(1998, 6, 4), LocalTime.of(8, 3, 31), systemUTC().zone()) .toInstant().toEpochMilli(), value.longValue()); }
From source file:com.qwazr.externalizor.SimpleTime.java
public SimpleTime() { calNullValue = null;/*from w w w.ja va 2 s. c o m*/ calValue = Calendar.getInstance(); calValue.setTimeInMillis(RandomUtils.nextLong()); calArray = new Calendar[] { calNullValue, calValue }; calList = new ArrayList(Arrays.asList(calValue, calNullValue)); dateNullValue = null; dateValue = new Date(RandomUtils.nextLong()); dateArray = new Date[] { dateNullValue, dateValue }; dateList = new ArrayList(Arrays.asList(dateValue, dateNullValue)); durationNullValue = null; durationValue = Duration.ofSeconds(RandomUtils.nextLong()); durationArray = new Duration[] { durationNullValue, durationValue }; durationList = new ArrayList(Arrays.asList(durationValue, durationNullValue)); instantNullValue = null; instantValue = Instant.ofEpochSecond(RandomUtils.nextLong(0, Instant.MAX.getEpochSecond())); instantArray = new Instant[] { instantNullValue, instantValue }; instantList = new ArrayList(Arrays.asList(instantValue, instantNullValue)); localTimeNullValue = null; localTimeValue = LocalTime.of(RandomUtils.nextInt(0, 24), RandomUtils.nextInt(0, 60), RandomUtils.nextInt(0, 60)); localTimeArray = new LocalTime[] { localTimeNullValue, localTimeValue }; localTimeList = new ArrayList(Arrays.asList(localTimeValue, localTimeNullValue)); localDateNullValue = null; localDateValue = LocalDate.of(RandomUtils.nextInt(2000, 3000), RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 29)); localDateArray = new LocalDate[] { localDateNullValue, localDateValue }; localDateList = new ArrayList(Arrays.asList(localDateValue, localDateNullValue)); localDateTimeNullValue = null; localDateTimeValue = LocalDateTime.of( LocalDate.of(RandomUtils.nextInt(2000, 3000), RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 29)), LocalTime.of(RandomUtils.nextInt(0, 24), RandomUtils.nextInt(0, 60), RandomUtils.nextInt(0, 60))); localDateTimeArray = new LocalDateTime[] { localDateTimeNullValue, localDateTimeValue }; localDateTimeList = new ArrayList(Arrays.asList(localDateTimeValue, localDateTimeNullValue)); monthDayNullValue = null; monthDayValue = MonthDay.of(RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 29)); monthDayArray = new MonthDay[] { monthDayNullValue, monthDayValue }; monthDayList = new ArrayList(Arrays.asList(monthDayValue, monthDayNullValue)); periodNullValue = null; periodValue = Period.of(RandomUtils.nextInt(0, Year.MAX_VALUE), RandomUtils.nextInt(1, 13), RandomUtils.nextInt(1, 29)); periodArray = new Period[] { periodNullValue, periodValue }; periodList = new ArrayList(Arrays.asList(periodValue, periodNullValue)); yearNullValue = null; yearValue = Year.of(RandomUtils.nextInt(0, Year.MAX_VALUE)); yearArray = new Year[] { yearNullValue, yearValue }; yearList = new ArrayList(Arrays.asList(yearValue, yearNullValue)); }