Java Time Format getFormatDatetime()

Here you can find the source of getFormatDatetime()

Description

get Format Datetime

License

Open Source License

Exception

Parameter Description
Exception an exception

Declaration

public static String getFormatDatetime() throws Exception 

Method Source Code

//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;

    }
}

Related

  1. getDefaultPropertyPageDateTimeFormat()
  2. getEndDate(String time, SimpleDateFormat dateFormat)
  3. getFormat2TimetagStr()
  4. getFormatDate(Date date, boolean ShowTimePart_in)
  5. getFormatDate(String timeString, String format)
  6. getFormatDateTime(Date date)
  7. getFormatDateTime(Date date, String format)
  8. getFormatDateTime(java.util.Date date)
  9. getFormattedCurrentDateAndTime()