首页 技术 正文
技术 2022年11月16日
0 收藏 899 点赞 4,394 浏览 635 个字

使用字符串初始化Date
String dateString = “2018-02-23”;
Date date= new SimpleDateFormat(“yyyy-MM-dd”).parse(dateString);

使用时间戳初始化
Date date = new Date(时间戳);

计算两个日期相差天数
long day = date1.getTime() – date2.getTime()) / (24*60*60*1000) + 1;

使用Calendar
Calendar calendar=Calendar.getInstance();
Date date=calendar.getTime);

获取年月日
calendar.get(Calendar.YEAR);
alendar.get(Calendar.MONTH) + 1;
calendar.get(Calendar.DAY_OF_MONTH);
calendar.get()方法
calendar.get(Calendar.DAY_OF_WEEK); 当前周的第几天
calendar.get(Calendar.DAY_OF_MONTH); 当前月的第几天
calendar.get(Calendar.DAY_OF_YEAR); 当前年的第几天
calendar.add(field1,field2)方法
add方法可以修改当前的日期
field1指定修改的字段,可以为Calendar.DAY_OF_WEEK,DAY_OF_MONTH
filed2可以增加或减少天数,为int型

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894