1 import java.text.ParseException;
 2 import java.text.SimpleDateFormat;
 3 import java.util.Calendar;
 4 import java.util.Date;
 5 
 6 public class dateToMill {
 7 public static void main(String[] args) {
 8 
 9     use();
10 
11 //    noUse();
12 
13 }
14 
15 //使用API计算
16 public static void use(){
17 Calendar calendar = Calendar.getInstance();
18 System.out.println(calendar);
19 Date date = new Date();
20 //设置时间2015.3.1 
21 calendar.set(2015, (3-1), 1); //月份从0开始
22 date = calendar.getTime();
23 System.out.println("设置时间:"+date);
24 
25 //计算13个月6天后,是周几
26 calendar.add(Calendar.MARCH, 13);
27 calendar.add(Calendar.DAY_OF_YEAR, 6);
28 System.out.println("今天是周"+(calendar.get(Calendar.DAY_OF_WEEK)-1)); //星期从周日开始
29 
30 //距离现在(2015.3.1)秒数
31 long time1 = calendar.getTimeInMillis(); //calendar对象表示的时间距1970.1.10点的毫秒数 (2016.4.7)
32 long time2 = date.getTime(); //date对象表示的时间距1970.1.10点的毫秒数    (2015.3.1)
33 long time = (time1 - time2) /1000;
34 System.out.println(time);
35 }
36 
37 //不使用API计算
38 public static void noUse(){
39 
40 try {
41 //设置时间2015.3.1
42 Date date1 = (new SimpleDateFormat("yyyy年MM月dd日").parse("2015年3月1日"));
43 System.out.println("设置时间:"+date1);
44 
45 //计算13个月6天后是周几
46 Date date2 = (new SimpleDateFormat("yyyy年MM月dd日").parse("2016年4月7日"));
47 
48 //获取SimpleDateFormat时间的年月日
49 /*SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy");
50 SimpleDateFormat sdf1 = new SimpleDateFormat("MM");
51 SimpleDateFormat sdf2= new SimpleDateFormat("dd");
52 String str1 = sdf0.format(date2);
53 String str2 = sdf1.format(date2);
54 String str3 = sdf2.format(date2);
55 System.out.println("年份为:"+str1);
56 System.out.println("月份为:"+str2);
57 System.out.println("日为:"+str3);*/
58 
59 System.out.println("期待时间:"+date2);
60 
61 //使用默认时区和语言环境这种方法获得一个日历
62 Calendar calendar = Calendar.getInstance();
63 calendar.setTime(date2);
64 
65 //默认国际通用以周日作为一周的开始
66 System.out.println("是周"+(calendar.get(Calendar.DAY_OF_WEEK)-1));
67 
68 //距离现在(2015.3.1)秒数
69 long time = (date2.getTime() - date1.getTime())/1000;
70 System.out.println("秒数:"+time);    
71 
72 } catch (ParseException e) {
73 e.printStackTrace();
74 }
75 }}

转自:https://blog.csdn.net/pjz161026/article/details/54973161

 

posted @ 2018-08-16 15:59 闻长歌而知雅意 阅读(1185) 评论(0) 推荐(0) 编辑
摘要: -- 启用dblink模块 CREATE EXTENSION dblink; -- 创建dblink连接 -- format: 'dbname=mydb host=myhost user=myuser password=mypassword' -- 请替换mydb, myhost, myuser, 阅读全文
posted @ 2024-03-27 17:12 闻长歌而知雅意 阅读(582) 评论(0) 推荐(0) 编辑
摘要: 1.导入pom依赖 <!-- easy excel依赖 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.6</version> </dependency> 阅读全文
posted @ 2022-12-22 14:46 闻长歌而知雅意 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 恢复内容开始 1.设置maven <!-- include central so that it is searched before our alternate repos --> <repository> <id>central</id> <name>Maven Repository Switc 阅读全文
posted @ 2022-06-15 10:51 闻长歌而知雅意 阅读(689) 评论(0) 推荐(0) 编辑
摘要: --创建自增序列create sequence id_seq start with 1 increment by 1 no minvalue no maxvalue cache 1; --将序列加到table的字段alter table table alter column id set defau 阅读全文
posted @ 2022-01-19 09:50 闻长歌而知雅意 阅读(174) 评论(0) 推荐(0) 编辑
摘要: #config druid#连接池的设置#初始化时建立物理连接的个数spring.datasource.druid.initial-size=5#最小连接池数量spring.datasource.druid.min-idle=5spring.datasource.druid.max-active=2 阅读全文
posted @ 2022-01-07 16:48 闻长歌而知雅意 阅读(342) 评论(0) 推荐(0) 编辑
摘要: /** * @author Leon */ @WebFilter(filterName = "WebFilter", urlPatterns = "/*") class WebsFilter implements Filter { @Autowired private ILogsService lo 阅读全文
posted @ 2021-12-22 11:17 闻长歌而知雅意 阅读(532) 评论(0) 推荐(0) 编辑
摘要: 1 @Target({ElementType.PARAMETER, ElementType.METHOD}) 2 @Retention(RetentionPolicy.RUNTIME) 3 @Documented 4 public @interface Log { 5 6 /** 7 * 是否记录日 阅读全文
posted @ 2021-12-22 10:53 闻长歌而知雅意 阅读(492) 评论(0) 推荐(1) 编辑
摘要: 限流 限流是对某一时间窗口内的请求数进行限制,保持系统的可用性和稳定性,防止因流量暴增而导致的系统运行缓慢或宕机。常用的限流算法有令牌桶和和漏桶,而Google开源项目Guava中的RateLimiter使用的就是令牌桶控制算法。 在开发高并发系统时有三把利器用来保护系统:缓存、降级和限流 缓存:缓 阅读全文
posted @ 2021-11-10 16:09 闻长歌而知雅意 阅读(513) 评论(3) 推荐(1) 编辑
摘要: 核心概念 Server:又称Broker,接受客户端的连接,实现AMQP实体服务 Connection:连接,应用程序与Broker的网络连接 Channel:网络信道,几乎所有的操作都在Channel中进行,Channel是进行消息读写的通道。客户端可建立多个Channel,每个Channel代表 阅读全文
posted @ 2021-07-02 00:51 闻长歌而知雅意 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 1. 更新基本系统 安装任何软件包之前,建议使用以下命令更新软件包和存储库 yum -y update 2. 安装Erlang 由于RabbitMQ是基于Erlang(面向高并发的语言)语言开发,所以在安装RabbitMQ之前,需要先安装Erlang。在本教程中我们将安装最新版本的Erlang到服务 阅读全文
posted @ 2021-06-24 19:01 闻长歌而知雅意 阅读(333) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示