• 获取系统时间的工具类


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

  • 相关阅读:
    Java 简单算法--打印乘法口诀(只使用一次循环)
    Java简单算法--求100以内素数
    ubuntu 16.04 chrome flash player 过期
    java 网络API访问 web 站点
    java scoket (UDP通信模型)简易聊天室
    leetcode1105 Filling Bookcase Shelves
    leetcode1140 Stone Game II
    leetcode1186 Maximum Subarray Sum with One Deletion
    leetcode31 Next Permutation
    leetcode834 Sum of Distances in Tree
  • 原文地址:https://www.cnblogs.com/Jiphen/p/2593810.html
Copyright © 2020-2023  润新知