Java SQL Date Create getSysdate(String format)

Here you can find the source of getSysdate(String format)

Description

get Sysdate

License

Open Source License

Declaration

public static String getSysdate(String format) 

Method Source Code

//package com.java2s;
/*//  w  w w.j  ava 2  s . c om
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     *
     * @return String
     * @throws Exception if error
     */
    public static String getSysdate() throws Exception {
        Calendar calendar = Calendar.getInstance();
        return convertDateToString(calendar.getTime());
    }

    public static String getSysdate(String format) {
        String selectTocharSysdate = "select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') from dual";
        long time = System.currentTimeMillis();
        java.sql.Date date = new java.sql.Date(time);
        return convertDateToString(date, format);
    }

    /**
     *
     * @param date to convert
     * @return String
     * @throws Exception if error
     */
    public static String convertDateToString(Date date) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        if (date == null) {
            return "";
        }
        try {
            return dateFormat.format(date);
        } catch (Exception e) {
            throw e;
        }
    }

    public static String convertDateToString(Date date, String pattern) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        if (date == null) {
            return "";
        }
        try {
            return dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}

Related

  1. getSqlDate()
  2. getSqlDate()
  3. getSQLDate()
  4. getSysDate()
  5. getSysDate()
  6. getSysDateGMTToday()
  7. getTodayDate()
  8. getTodayDate()
  9. getTodaySqlDate()