Java examples for Date Time:SimpleDateFormat
Formatting seconds using SimpleDateFormat
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) { Date date = new Date(); /* w w w. j a va 2 s . c o m*/ //formatting seconds in s format like 1,2 etc. String strDateFormat = "s"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("seconds in s format : " + sdf.format(date)); //formatting seconds in ss format like 01, 02 etc. strDateFormat = "ss"; sdf = new SimpleDateFormat(strDateFormat); System.out.println("seconds in ss format : " + sdf.format(date)); } }