Here you can find the source of createDateTime(int year, int month, int day, int hour, int minute, int second, String timezone)
public static Date createDateTime(int year, int month, int day, int hour, int minute, int second, String timezone)
//package com.java2s; //License from project: BSD License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static Date createDateTime(int year, int month, int day, int hour, int minute, int second, String timezone) {/*from ww w .j ava 2s. c om*/ TimeZone zone = null; if (timezone != null && !timezone.isEmpty()) { zone = TimeZone.getTimeZone(timezone); } if (zone == null) { zone = TimeZone.getDefault(); } Calendar calendar = Calendar.getInstance(zone); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthNumber(month)); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); Date date = calendar.getTime(); return date; } public static int monthNumber(int month) { switch (month) { case 1: return Calendar.JANUARY; case 2: return Calendar.FEBRUARY; case 3: return Calendar.MARCH; case 4: return Calendar.APRIL; case 5: return Calendar.MAY; case 6: return Calendar.JUNE; case 7: return Calendar.JULY; case 8: return Calendar.AUGUST; case 9: return Calendar.SEPTEMBER; case 10: return Calendar.OCTOBER; case 11: return Calendar.NOVEMBER; case 12: return Calendar.DECEMBER; default: return -1; } } }