List of usage examples for java.time.format DateTimeFormatter ofPattern
public static DateTimeFormatter ofPattern(String pattern, Locale locale)
From source file:Main.java
public static void main(String[] args) { // 2014-04-01 10:45 LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45); // french date formatting (1. avril 2014) String frenchDate = dateTime.format(DateTimeFormatter.ofPattern("d. MMMM yyyy", new Locale("fr"))); System.out.println(frenchDate); }
From source file:Main.java
public static void format(Temporal co, String pattern) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US); String str = fmt.format(co);//from ww w. j a va2s . co m System.out.println(pattern + ": " + str); }
From source file:org.nodatime.tzvalidate.Java8Dump.java
@Override public ZoneTransitions getTransitions(String id, int fromYear, int toYear) { ZoneId zone = ZoneId.of(id); ZoneRules rules = zone.getRules(); DateTimeFormatter nameFormat = DateTimeFormatter.ofPattern("zzz", Locale.US); ZoneTransitions transitions = new ZoneTransitions(id); Instant start = ZonedDateTime.of(fromYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); transitions.addTransition(null, rules.getOffset(start).getTotalSeconds() * 1000, rules.isDaylightSavings(start), nameFormat.format(start.atZone(zone))); Instant end = ZonedDateTime.of(toYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); ZoneOffsetTransition transition = rules.nextTransition(start.minusNanos(1)); while (transition != null && transition.getInstant().isBefore(end)) { Instant instant = transition.getInstant(); transitions.addTransition(new Date(instant.toEpochMilli()), rules.getOffset(instant).getTotalSeconds() * 1000, rules.isDaylightSavings(instant), nameFormat.format(instant.atZone(zone))); transition = rules.nextTransition(instant); }// ww w.ja v a2 s . c om return transitions; }
From source file:org.talend.dataquality.statistics.datetime.DateTimePatternManager.java
private static Map<DateTimeFormatter, String> loadDateFormats(String patternFileName) throws IOException { Map<DateTimeFormatter, String> parsers = new LinkedHashMap<DateTimeFormatter, String>(); InputStream stream = DateTimePatternManager.class.getResourceAsStream(patternFileName); List<String> lines = IOUtils.readLines(stream); for (String line : lines) { if (!"".equals(line.trim())) { String[] localePatternText = line.trim().split("\t"); parsers.put(//from ww w .j a v a2s. c o m DateTimeFormatter.ofPattern(localePatternText[1], getLocaleFromStr(localePatternText[0])), localePatternText[1]); } } stream.close(); return parsers; }
From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java
@Override public void preTaskActivated(ITask task) { LocalDateTime now = LocalDateTime.now(); String startString = Activator.getValue(task, Activator.START); String tickString = Activator.getValue(task, Activator.TICK); if (startString != null) { LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime stopped = LocalDateTime.now(); long seconds = ticked.until(stopped, ChronoUnit.SECONDS); String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?", "Work was already started and task was last updated on " + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US)) + ". Continue and add the elapsed time since (" + time + ") to the task total?"); if (confirm) { Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS)); }//from w w w . j a v a 2s. co m } Activator.setValue(task, Activator.TICK, now.toString()); Activator.setValue(task, Activator.START, now.toString()); }
From source file:com.haulmont.chile.core.datatypes.impl.LocalDateDatatype.java
@Override protected DateTimeFormatter getDateTimeFormatter(FormatStrings formatStrings, Locale locale) { return DateTimeFormatter.ofPattern(formatStrings.getDateFormat(), locale); }
From source file:de.elbe5.base.util.StringUtil.java
public static String toHtmlDate(LocalDateTime date, Locale locale) { if (date == null) return ""; if (locale == null) locale = Locales.getInstance().getDefaultLocale(); return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd", locale)); }
From source file:de.elbe5.base.util.StringUtil.java
public static String toHtmlTime(LocalDateTime date, Locale locale) { if (date == null) return ""; if (locale == null) locale = Locales.getInstance().getDefaultLocale(); return date.format(DateTimeFormatter.ofPattern("HH:mm:ss", locale)); }
From source file:de.elbe5.base.util.StringUtil.java
public static String toHtmlDateTime(LocalDateTime date, Locale locale) { if (date == null) return ""; if (locale == null) locale = Locales.getInstance().getDefaultLocale(); return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", locale)); }
From source file:fr.lepellerin.ecole.web.controller.cantine.DetaillerReservationRepasController.java
@RequestMapping(value = "/reserver") @ResponseBody/* w w w .ja v a 2s .co m*/ public ResponseEntity<String> reserver(@RequestParam final String date, @RequestParam final int individuId) throws TechnicalException { final CurrentUser user = (CurrentUser) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); final LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern(GeDateUtils.DATE_FORMAT_YYYYMMDD, Locale.ROOT)); String result; try { result = this.cantineService.reserver(localDate, individuId, user.getUser().getFamille(), null); return ResponseEntity.ok(result); } catch (FunctionalException e) { LOGGER.error("Une erreur fonctionnelle s'est produite : " + e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); } }