博客
关于我
Java处理时间Date
阅读量:541 次
发布时间:2019-03-09

本文共 1102 字,大约阅读时间需要 3 分钟。

import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class DateParserT {    public static void main(String[] args) {        Date dt = new Date();        System.out.println(dt); // 格式:Wed Jul 06 09:28:19 CST 2016        String formatDate = null;        String dateStr = "2016-07-06";        String FormatStr = "yyyy-MM-dd";        SimpleDateFormat dFormat = new SimpleDateFormat(FormatStr);        try {            Date date = dFormat.parse(dateStr);            System.out.println(date);// 格式:2016-07-06            System.out.println(dFormat.format(date));        } catch (ParseException e) {            e.printStackTrace();        }        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");        SimpleDateFormat sdf2 = new SimpleDateFormat("HHmmss");        Date currentTime = new Date();        String datastring = sdf.format(currentTime); // 格式:20160706094333        String onlyStr = datastring.replace(" ", "");        String subStr = onlyStr.substring(1); // 格式:1467770970        System.out.println(subStr);    }}

转载地址:http://reliz.baihongyu.com/

你可能感兴趣的文章
Objective-C实现anagrams字谜算法(附完整源码)
查看>>
Objective-C实现ApproximationMonteCarlo蒙特卡洛方法计算pi值算法 (附完整源码)
查看>>
Objective-C实现area under curve曲线下面积算法(附完整源码)
查看>>
Objective-C实现argmax函数功能(附完整源码)
查看>>
Objective-C实现arithmetic算术算法(附完整源码)
查看>>
Objective-C实现armstrong numbers阿姆斯壮数算法(附完整源码)
查看>>
Objective-C实现articulation-points(关键点)(割点)算法(附完整源码)
查看>>
Objective-C实现atoi函数功能(附完整源码)
查看>>
Objective-C实现average absolute deviation平均绝对偏差算法(附完整源码)
查看>>
Objective-C实现average mean平均数算法(附完整源码)
查看>>
Objective-C实现average median平均中位数算法(附完整源码)
查看>>
Objective-C实现average mode平均模式算法(附完整源码)
查看>>
Objective-C实现avl 树算法(附完整源码)
查看>>
Objective-C实现AvlTree树算法(附完整源码)
查看>>
Objective-C实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
查看>>
Objective-C实现BACKTRACKING 方法查找集合的幂集算法(附完整源码)
查看>>
Objective-C实现bailey borwein plouffe算法(附完整源码)
查看>>
Objective-C实现balanced parentheses平衡括号表达式算法(附完整源码)
查看>>