Date <-> String
来源:互联网 发布:淘宝客返利海报 编辑:程序博客网 时间:2024/04/29 15:28
1. String convert to Date
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
try {
Date date = (Date) formatter.parse(processDate);
} catch (ParseException e) {
e.printStackTrace();
}
2.Date convert to String
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
Date tmpDate = new Date();
String strDate = formatter.format(tmpDate) ;
3.Calendar Date 几个用法
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); //date :任何一个Date
calendar.set(Calendar.DAY_OF_MONTH, 1); // date 这个月的第一天
Date firstDayOfMonth = calendar.getTime(); //得到第一天的日期
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//date这个月总天数
//get the day of week by the date , 该date是所在星期内的第几天, sunday 是1, saturday 是7
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
//以date为基准,找它之后的第几天是几号, 例如,9月1号后的第0天是9月1号,9月1号后的第一天是9月2号,9月1号后的第2天是9月3号,依次类推, daySeek 就是第几天
public static Date seekDateByDay(Date date,int daySeek){
if(date == null){
return null;
}
Calendar seekedDate = Calendar.getInstance();
seekedDate.setTime(date);
seekedDate.set(Calendar.DAY_OF_MONTH, seekedDate.get(Calendar.DAY_OF_MONTH)+daySeek);
return seekedDate.getTime();
}
- Date <-> String
- String & Date
- javase Date--->string ||String --->Date
- date 转成String ,String 转成date
- javascript date 转 string ,string 转 date
- String 转换 Date 和Date转换String
- Date转String / String 转Date
- Date转String String 转Date
- 时间转换String-date Date-String
- String转Date、Date转String以及Date比较
- 将String类型Date
- String转为Date
- long string date转换
- Date long String 转换
- String Date 相互转换
- data+String = date
- String 转 Date
- Date,DateStamp,String转换
- VMware Workstation 7.1 正式版发布(下载带序列号)
- Apache虚拟主机和目录的设置
- 分布式缓存系统Memcached
- ZOJ 3317 Murder in Restaurant模拟(解题报告)
- 不公平的社会
- Date <-> String
- java去除字符串中的空格、回车、换行符、制表符
- 修复/etc/svc/repository.db
- 程序员技术练级攻略
- CT和PT的作用,符号?
- Jexi计划
- ffmpeg详解
- 【网站制作视频教程】-第15讲 html框架技术!-传智播客
- 布隆过滤器 (Bloom Filter) 详解