All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.phoenix.utils.GetNow Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package org.phoenix.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 获取当前时间,并以各种形式返回。
* 并且可以对时间差进行计算
* @author mengfeiyang * */ public class GetNow { /** * 返回默认的当前的时间。返回格式为:yyyy-MM-dd HH:mm:ss
* @author mengfeiyang * @return */ public static String getCurrentTime(){ SimpleDateFormat sdf = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE); sdf.applyPattern("yyyy-MM-dd HH:mm:ss"); //sdf.applyPattern("HH:mm:ss,SSS"); Date currDate = new Date(); String timeStr = sdf.format(currDate); return timeStr; } /** * 将当前获得的毫秒数转换成指定格式的时间.
* 如:"yyyy-MM-dd HH:mm:ss"
* @author mengfeiyang * @param PATTERN * @return */ public static String getCurrentTime(String PATTERN){ SimpleDateFormat sdf = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE); sdf.applyPattern(PATTERN); Date currDate = new Date(); String timeStr = sdf.format(currDate); return timeStr; } public static String getFormatTime(Date date){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); return sdf.format(date); } /** * 将指定的毫秒数转换成指定格式的时间.
* 如:"yyyy-MM-dd HH:mm:ss"
* @author mengfeiyang * @param PATTERN * @return */ public static String getCurrentTime(long time,String PATTERN){ SimpleDateFormat sdf = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE); sdf.applyPattern(PATTERN); String timeStr = sdf.format(time); return timeStr; } /** * 将指定的时间转换成long * @param date * @param pattern * @return * @throws ParseException */ public static long currentTimeToLong(String date,String pattern) throws ParseException{ SimpleDateFormat sf = new SimpleDateFormat(pattern); return sf.parse(date).getTime(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy