Java examples for java.util:Date Format
Format Date to String in yyyy-MM-dd HH:mm:ss format and set timezone
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static void main(String[] argv) { Date inputTime = new Date(); System.out.println(date2Str(inputTime)); }// w ww. j ava2 s. com private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; public static String date2Str(Date inputTime) { SimpleDateFormat inputFormat = new SimpleDateFormat( YYYY_MM_DD_HH_MM_SS); inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); return inputFormat.format(inputTime); } }