Based on date and timezone return ZonedDateTime instance. - Java java.time

Java examples for java.time:ZonedDateTime

Description

Based on date and timezone return ZonedDateTime instance.

Demo Code


//package com.java2s;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter
            .ofPattern("yyyy-MM-dd HH:mm:ss VV");
    private static final String SPACE = " ";

    /**//from  ww  w  .j av a 2  s .c o  m
     * Based on date and timezone return ZonedDateTime instance.
     * 
     * @param date
     * @param timezone
     * @return
     */
    public static ZonedDateTime getZonedDateTime(final String date,
            final String timezone) {
        final ZonedDateTime zonedDateTime = ZonedDateTime.parse(
                concatStrings(date, SPACE, timezone), DATE_TIME_FORMATTER);
        return zonedDateTime;
    }

    /**
     * Supply any number of String, this method would return string by concatenating all of them.
     * 
     * @param strings
     * @return
     */
    private static String concatStrings(final String... strings) {
        final StringBuilder stringBuilder = new StringBuilder();
        for (String string : strings) {
            stringBuilder.append(string);
        }
        return stringBuilder.toString();
    }
}

Related Tutorials