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;
        }
    }

  • 相关阅读:
    远程登陆服务——SSH
    A web-based 3D modeling framework for a runner-gate design( 一种基于web的三维建模框架)
    Vue+Element+Echarts+Springboot+微信小程序开发(肿瘤医学项目)
    基于拖放布局的 Twitter Bootstrap 网站生成器
    Ubuntu下git使用华为云/gitee/github
    在 Ubuntu 18.04 上安装 Postman
    在Ubuntu 18.04上安装Git与入门教程
    转载:渲染层和逻辑层
    Ubuntu系统中安装Neo4j
    NosqlBooster连接数据库失败connect ECONNREFUSED 127.0.0.1:27017——mongodb连接失败
  • 原文地址:https://www.cnblogs.com/Jiphen/p/2593810.html
Copyright © 2011-2022 走看看