zoukankan      html  css  js  c++  java
  • 获取系统时间的工具类

    package com.page.util;

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.util.Locale;

    /**
     * @description 得到当前系统时间的工具类
     * @author BrinPage
     * @version 2
     * @time 2012.7.12
     */
    public class CurrentTime {
        
        /**
         * 返回当前时间
         * @return 以字符串的形式返回当前时间
         */
        public String getCurrentTime(){
            Date date = new Date();
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.CHINA);
            return dateFormat.format(date);
        }
        
        /**
         * 返回当前日期
         * @return 以字符串的形式返回当前日期
         */
        public String getCurrentDate(){
            Date date = new Date();
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.CHINA);
            return dateFormat.format(date);
        }
        
        /**
         * 返回指定日期
         * @return 以字符串的形式返回指定日期
         */
        public String getOtherDate(Date date, int i){
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.CHINA);
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);
            cal.add(Calendar.DAY_OF_MONTH, i);
            return dateFormat.format(cal.getTime());
        }
        
        /**
         * 返回指定日期月/日
         * @return 以字符串的形式返回指定日期
         */
        public String getOtherMonDate(Date date, int i){
            DateFormat dateFormat = new SimpleDateFormat("M/dd", Locale.CHINA);
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);
            cal.add(Calendar.DAY_OF_MONTH, i);
            return dateFormat.format(cal.getTime());
        }

      /**

       * 通过字符串获取指定格式的时间

       **/

      public Date stringToDate(String time){
            Date date = null;
            SimpleDateFormat timeFormat = null;
            timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                date = timeFormat.parse(time);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return date;
        }
    }

  • 相关阅读:
    前端使用 node-gyp 构建 Native Addon
    CHANGELOG 的实现
    深入 JavaScript 中的对象以及继承原理
    使用electron进行原生应用的打包(2)---主进程与渲染进程之间的通信
    使用electron进行原生应用的打包
    Babel编译
    HTML布局四剑客-Flex,Grid,Table,Float
    关于vtt 与 srt 字幕 的相互转换
    关于websocket
    关于jQuery中nth-child和nth-of-type的详解
  • 原文地址:https://www.cnblogs.com/Jiphen/p/2593810.html
Copyright © 2011-2022 走看看