zoukankan      html  css  js  c++  java
  • java实现获取当前年月日 小时 分钟 秒 毫秒

    java代码实现如下

        /**
         * 英文简写(默认)如:2010-12-01
         */
        public static String FORMAT_SHORT = "yyyy-MM-dd";
         
        /**
         * 英文全称  如:2010-12-01 23:15:06
         */
        public static String FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
         
        /**
         * 精确到毫秒的完整时间    如:yyyy-MM-dd HH:mm:ss.S
         */
        public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
         
        /**
         * 中文简写  如:2010年12月01日
         */
        public static String FORMAT_SHORT_CN = "yyyy年MM月dd";
         
        /**
         * 中文全称  如:2010年12月01日  23时15分06秒
         */
        public static String FORMAT_LONG_CN = "yyyy年MM月dd日  HH时mm分ss秒";
         
        /**
         * 精确到毫秒的完整中文时间
         */
        public static String FORMAT_FULL_CN = "yyyy年MM月dd日  HH时mm分ss秒SSS毫秒";
     
     
     
     
     
     
     
     
    /**
       * 获取时间戳
       */
    public static String getTimeString() {
        SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
        Calendar calendar = Calendar.getInstance();
        return df.format(calendar.getTime());
    }
     
    /**
     * 获取日期年份
     * @param date 日期
     * @return
     */
    public static String getYear(Date date) {
        return format(date).substring(04);
    }
    /**
     * 功能描述:返回月
     *
     * @param date
     *            Date 日期
     * @return 返回月份
     */
    public static int getMonth(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MONTH) + 1;
    }
     
    /**
     * 功能描述:返回日
     *
     * @param date
     *            Date 日期
     * @return 返回日份
     */
    public static int getDay(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_MONTH);
    }
     
    /**
     * 功能描述:返回小
     *
     * @param date
     *            日期
     * @return 返回小时
     */
    public static int getHour(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }
     
    /**
     * 功能描述:返回分
     *
     * @param date
     *            日期
     * @return 返回分钟
     */
    public static int getMinute(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MINUTE);
    }
     
    /**
     * 返回秒钟
     *
     * @param date
     *            Date 日期
     * @return 返回秒钟
     */
    public static int getSecond(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.SECOND);
    }
     
    /**
     * 功能描述:返回毫
     *
     * @param date
     *            日期
     * @return 返回毫
     */
    public static long getMillis(Date date) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getTimeInMillis();
    }
  • 相关阅读:
    Linux命令 tr
    Linux命令 xargs
    Python 文件读写 文件和路径
    Python 正则表达式 匹配任意字符
    Python 正则表达式 贪心匹配和非贪心匹配
    Python 正则表达式 匹配次数
    Python 正则表达式 利用括号分组
    Python 正则表达式 search vs match
    【转-整理】 SQL2008 提示评估期已过的解决方法
    Java http接口进阶——自我理解为接口框架形式
  • 原文地址:https://www.cnblogs.com/jpfss/p/10451820.html
Copyright © 2011-2022 走看看