Here you can find the source of formatToSec(Date date)
public static String formatToSec(Date date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String formatToSec(Date date) { return format(date, "yyyyMMdd_HHmmss"); }/* ww w . ja va 2s . co m*/ public static String format(Date date, String format) { String dateString = null; if (null != date) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); dateString = simpleDateFormat.format(date); } return dateString; } }