日期/时间格式化操作
来源:互联网 发布:淘宝宝贝卖点大全 编辑:程序博客网 时间:2024/05/24 07:21
格式化输出当前日期、时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); //指定日期格式SimpleDateFormat sdf1 = new SimpleDateFormat("HHmmss"); //指定时间格式 SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd:HHmmss"); //指定日期、时间格式Calendar cal = Calendar.getInstance(); //获取当前日期、时间String curDate = null;String curtime = null;String date = null; date = sdf2.format(cal.getTime); //格式化输入时间curtime = sdf1.format(cal.getTime()); //格式化输出时间curDate = sdf.format(cal.getTime()); //格式化输出日期获取几日后或几小时后的时间或日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");SimpleDateFormat sdf1 = new SimpleDateFormat("HHmmss");SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd:HHmmss");Calendar cal = Calendar.getInstance();String curDate = null;String curtime = null;String date = null;cal.add(Calendar.DATE, Integer.parseInt(validTime)); //当前几天后或几天前(例2或者-2)日期,参数2为对应天数cal.add(Calendar.HOUR, Integer.parseInt(validTime)); //几小时候或者几小时前,参数2为对应小时数curtime = sdf1.format(cal.getTime()); curDate = sdf.format(cal.getTime());date = sdf2.format(cal.getTime);获取当前时间戳
long timeFlag = System.currentTimeMillis();获取指定日期时间戳
public static void main(String[] arg) throws ParseException{ SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd"); Date date=simpleDateFormat .parse("2010-06-25"); int timeStemp = date.getTime(); System.out.println(timeStemp );}
0 0
- 时间日期格式化操作
- 日期/时间格式化操作
- 格式化时间日期函数
- 时间日期格式化
- JAVA格式化时间日期
- 格式化时间日期
- .net日期时间格式化
- rails 格式化日期时间
- 格式化 日期时间 DateTime
- Mysql 格式化日期/时间
- C#格式化日期时间
- Mysql 格式化日期/时间
- C#日期格式化,时间
- JAVA格式化日期时间
- Python格式化日期时间
- C#日期时间格式化
- C#日期时间格式化
- Python 日期时间格式化
- [BZOJ2674]Attack(整体二分+树状数组套线段树)
- 二分贪心—E
- 百度地图定位
- HDU
- 加入toolbar报错
- 日期/时间格式化操作
- springAOP的注解版
- Android Studio 中 An error occurred while creating the AVD.See idea.log for detail
- 一个AndroidDemo(百分比 照片 广播 通知 沉浸式标题栏 对话 退出 .9 聊天等等)
- MVC传值到js
- iOS网络请求中的错误处理
- ShopShowDemo
- 第六届蓝桥杯决赛试题-机器人繁殖
- 帧动画