Here you can find the source of toDate(int date, String timeFormat)
public static Date toDate(int date, String timeFormat)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String yyyyMMdd = "yyyyMMdd"; public static Date toDate(int date, String timeFormat) { StringBuilder sbBuilder = new StringBuilder(); if (!yyyyMMdd.equals(timeFormat) && String.valueOf(date).length() == 8) { sbBuilder.append("0"); }// w w w.j ava2 s.co m sbBuilder.append(date); DateFormat sdf = new SimpleDateFormat(timeFormat); Date datetime = new Date(); try { datetime = sdf.parse(sbBuilder.toString()); } catch (ParseException e) { throw new RuntimeException("parse the time [" + date + "] with format [" + timeFormat + "] error", e); } return datetime; } public static Date toDate(int date, int time, String timeFormat) { StringBuilder sbBuilder = new StringBuilder(); sbBuilder.append(date); if (String.valueOf(time).length() == 8) { sbBuilder.append("0"); } sbBuilder.append(time); DateFormat sdf = new SimpleDateFormat(timeFormat); Date datetime = new Date(); try { datetime = sdf.parse(sbBuilder.toString()); } catch (ParseException e) { throw new RuntimeException( "parse the time [" + date + " " + time + "] with format [" + timeFormat + "] error", e); } return datetime; } }