/**
*
*/
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());
}
}

Date获取时间段的更多相关文章

  1. SQL 获取时间段内日期列表

    declare @start date,@end date; set @start='2010-01-01'; set @end='2010-02-01'; --获取时间段内日期列表 select [ ...

  2. js通过Date获取日期

    获取当前系统时间 var myDate = new Date();//获取系统当前时间 获取特定格式日期 myDate.getYear(); //获取当前年份(2位) myDate.getFullYe ...

  3. PHP date()获取某时间段以周、月、季度为粒度的时间段数组

    date()函数: PHP date()  参考:https://www.hi-docs.com/php/date.html Linux date()参考:http://www.cnblogs.com ...

  4. php date()获取的时间不对解决办法

    因为php默认获取的是格林威治时间,与北京时间相差8小时. 我们要获取到北京时间有两个办法: 1.修改php.ini配置文件: 打开php.ini文件,一般在php配置根目录下,找到其中的 ;date ...

  5. linux在shell date获取时间的相关操作

    获得当天的日期 date +%Y-%m-%d 输出: 2011-07-28 将当前日期赋值给DATE变量DATE=$(date +%Y%m%d) 有时候我们需要使用今天之前或者往后的日期,这时可以使用 ...

  6. java Date获取 年月日时分秒

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. 根据时间段获取时间段内所有时间点(js)

    Date.prototype.format=function (){var s='';s+=this.getFullYear()+'-';// 获取年份.s+=(this.getMonth()+1)+ ...

  8. shell date 获取昨天日期

    使用date -d 选项:  date  +"%Y%m%d" -d  "+n days"         今天的后n天日期       date  +" ...

  9. bash 获取时间段内的日志内容

    需求,获取时段内的/var/log/messages文件内出现错误的消息,支持多行的消息,支持天,小时分钟,秒级的区间,可以修改监控的日志对象 #!/bin/bash if [ $# != 1 ] ; ...

随机推荐

  1. javascript 异步编程-setTimeout

    javascript的执行引擎是单线程的,正常情况下是同步编程的模式,即是程序按照代码的顺序从上到下依次顺序执行.只要有一个任务耗时很长,后面的任务都必须排队等着,会拖延整个程序的执行.常见的浏览器无 ...

  2. linux命令(9)设定固定ip

    一.使用命令设置ubuntu的ip地址 1.修改配置文件blacklist.conf禁用IPV6: sudo vi /etc/modprobe.d/blacklist.conf 2.在文档最后添加 b ...

  3. 深入Java集合学习系列:HashMap的实现原理

    1.    HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变 ...

  4. Yii 发送电子邮件

    yii 收发邮件 ------------------------------------------------------------------------------------------- ...

  5. 在Windows 7上安装MongoDB 2.6.7

    sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=\"C:\mongodb\ ...

  6. vs 2012 智能提示后为何不能 直接按enter键把提示的内容输入

    这个是VS的"建议完成模式"和"标准模式",两者间切换按快捷键:Ctrl+Alt+空格键

  7. centos 下安装.net core

    先要安装libunwind, libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,32位操作系统不要安装.其中包括用于输出堆栈跟踪的API.用于以编程方式辗转开解堆栈的 ...

  8. 微信JSSDK示例代码 笔记

    using System; using System.Collections.Generic; using System.Web; using System.IO; using System.Secu ...

  9. 源码解读—HashMap

    什么是HashMap ? hashMap是用什么基础数据结构实现的?HashMap是如何解决hashCode冲突的? hashMap的基础容器是数组+链表(transient Entry[] tabl ...

  10. (easy)LeetCode 258.Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...