get Thai Buddhist Date - Java java.time

Java examples for java.time:Buddhist

Description

get Thai Buddhist Date

Demo Code


//package com.java2s;
import java.text.SimpleDateFormat;
import java.time.chrono.ThaiBuddhistDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Main {
    public static final String DEFALUT_DATE_PATTERN = "dd-MMM-yyyy";

    public static String getThaiBuddhistDate(int thaiYear, int monthOfYear,
            int dayOfMonth, String pattern) {
        String date = null;//  w ww .  j a  va 2 s . com
        if (isNull(pattern)) {
            pattern = DEFALUT_DATE_PATTERN;
        }
        try {
            date = ThaiBuddhistDate.of(thaiYear, monthOfYear, dayOfMonth)
                    .format(DateTimeFormatter.ofPattern(pattern));
        } catch (Exception e) {

        }
        return date;
    }

    private static boolean isNull(String text) {
        return text == null || text.isEmpty();
    }

    public static String format(Date date, String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }
}

Related Tutorials