Here you can find the source of getFormatDatetime()
Parameter | Description |
---|---|
Exception | an exception |
public static String getFormatDatetime() throws Exception
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static String getFormatDatetime() throws Exception { GregorianCalendar gCalendar = new GregorianCalendar(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String strDateTime;//www . j ava 2 s. c o m try { strDateTime = formatter.format(gCalendar.getTime()); } catch (Exception ex) { System.out.println("Error Message:".concat(String.valueOf(String.valueOf(ex.toString())))); String s = null; return s; } return strDateTime; } public static String getTime() { Calendar calendar = Calendar.getInstance(); String strHour = "" + calendar.get(Calendar.HOUR_OF_DAY); if (strHour.length() == 1) strHour = "0" + strHour; String strMinute = "" + calendar.get(Calendar.MINUTE); if (strMinute.length() == 1) strMinute = "0" + strMinute; String strSecond = "" + calendar.get(Calendar.SECOND); if (strSecond.length() == 1) strSecond = "0" + strSecond; String curTime = strHour + strMinute + strSecond; return curTime; } }