Java ZoneId parseDateTime(String yyyymmdd, String hhmmss)

Here you can find the source of parseDateTime(String yyyymmdd, String hhmmss)

Description

parse Date Time

License

Open Source License

Declaration

public static ZonedDateTime parseDateTime(String yyyymmdd, String hhmmss) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    public static ZonedDateTime parseDateTime(String yyyymmdd, String hhmmss) {
        return parseDateTime(yyyymmdd, hhmmss, ZoneId.systemDefault());
    }//from ww w  . jav a2 s  .c  om

    public static ZonedDateTime parseDateTime(String yyyymmdd) {
        return parseDateTime(yyyymmdd, "00:00:00");
    }

    public static ZonedDateTime parseDateTime(String yyyymmdd, String hhmmss, String timezone) {
        return parseDateTime(yyyymmdd, hhmmss, determineTimeZoneId(timezone));
    }

    public static ZonedDateTime parseDateTime(String yyyymmdd, String hhmmss, ZoneId timezone) {
        if (yyyymmdd == null)
            return null;

        return LocalDateTime.parse(yyyymmdd + "T" + hhmmss, DateTimeFormatter.ISO_LOCAL_DATE_TIME).atZone(timezone);
    }

    public static ZoneId determineTimeZoneId(String zoneId) {
        try {
            return ZoneId.of(zoneId);
        } catch (Exception e) {//NOSONAR
            return ZoneId.systemDefault();
        }
    }
}

Related

  1. getZoneDateTime(Date d, String tzId)
  2. getZoneId()
  3. getZoneId(String tzId)
  4. now()
  5. parseBuildTimestamp(String buildTimestamp)
  6. parseDateToZdt(Date date)
  7. parseTimeZone(String timeZoneStr)
  8. slugifyDate(Long epochMillis)
  9. verifyZoneId(String zoneId)