zoukankan      html  css  js  c++  java
  • Date获取时间段

    /**
     * 
     */
    package com.chinabase.common.util;
    
    /**
     * @author yuanji
     * @created on:Sep 19, 2008
     */
    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    public class TimeFormat {
    
        /**
         * 获得当前时间精确到毫秒
         * 
         * @return
         */
        public static String getTimestamp() {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            return timestamp.toString();
        }
    
        /**
         * 生成文件夹名
         * 
         * @return
         */
        public static String toFileName() {
            return getTimestamp().replaceAll("-| |:|\.", "");
        }
    
        /**
         * 获得年-月-日
         * 
         * @return
         */
        public static String getDate() {
            return getTimestamp().substring(0, 10);
        }
    
        /**
         * 
         * @return 获取当月的第一天
         */
        public static String getFirstMonthDay(){
            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      
               Date date = new Date();
               Date da = new Date(date.getYear(),date.getMonth(),01);    
               Timestamp startTime=Timestamp.valueOf(df1.format(da));
               return startTime.toLocaleString();
        }
        //获取当月的最后-天
        public static String  getLastDayOfMonth()   {   
            Calendar cal = Calendar.getInstance(); 
            SimpleDateFormat datef=new SimpleDateFormat("yyyy-MM-dd");
                         cal.set( Calendar.DATE, 1 );
                         cal.roll(Calendar.DATE, - 1 );
                         Date endTime=cal.getTime();
                         String endTime1=datef.format(endTime)+" 23:59:59";
                        return endTime1;
    }  
        public static String getTime() {
            return getTimestamp().substring(11);
        }
    
        public static void main(String[] args) {
            System.out.println(TimeFormat.getTimestamp());
            System.out.println(TimeFormat.toFileName());
            System.out.println(TimeFormat.getDate());
            System.out.println(getTime());
            System.out.println(getTime().substring(0, 8));
            System.out.println(getLastDayOfMonth());
            System.out.println(getFirstMonthDay());
        }
    }
  • 相关阅读:
    XMPP即时通讯资料记录
    iOS 图片裁剪与修改
    iOS开发xcode报错:"xxxxxx"has been modified since the precompiled header was built
    模糊数学课件(清晰易懂)
    几个可用于数据挖掘和统计分析的java库
    java中list集合的内容,如何使用像数据库中group by形式那样排序
    spark java 代码example
    spark 编程向导
    一个深度学习博客
    Selenium2(WebDriver)_如何判断WebElement元素对象是否存在
  • 原文地址:https://www.cnblogs.com/kedoudejingshen/p/3511718.html
Copyright © 2011-2022 走看看