Java Date Now getCurrentDateStr(String pattern)

Here you can find the source of getCurrentDateStr(String pattern)

Description

get Current Date Str

License

Open Source License

Declaration

public static String getCurrentDateStr(String pattern) 

Method Source Code

//package com.java2s;
/*/*from  w w  w.  java2  s .c  o  m*/
 * Copyright 2012 The Solmix Project
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.gnu.org/licenses/ 
 * or see the FSF site: http://www.fsf.org. 
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String getCurrentDateStr(String pattern) {
        return getDateString(new Date(), pattern);
    }

    public static String getDateString(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String __return = null;
        try {
            __return = sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return __return;
    }

    public static String getDateString(long dateLong, String pattern) {
        Date date = new Date();
        date.setTime(dateLong);
        return getDateString(date, pattern);
    }

    public static String getDateString(long dateLong) {
        Date date = new Date();
        date.setTime(dateLong);
        return getDateString(date, "yyyy-MM-dd");
    }

    public static String getDateString(String dateLongStr) {
        Date date = new Date();
        date.setTime(Long.valueOf(dateLongStr));
        return getDateString(date, "yyyy-MM-dd");
    }
}

Related

  1. getCurrentDateSlashStr()
  2. getCurrentDateStr()
  3. getCurrentDateStr()
  4. getCurrentDateStr()
  5. getCurrentDateStr()
  6. getCurrentDateString()
  7. getCurrentDateString()
  8. getCurrentDateString()
  9. getCurrentDateString(String dateFormat)