博客
关于我
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实现BitMap算法(附完整源码)
查看>>
Objective-C实现bitmask位掩码算法(附完整源码)
查看>>
Objective-C实现bitonic sort双调排序算法(附完整源码)
查看>>
Objective-C实现BloomFilter布隆过滤器的算法(附完整源码)
查看>>
Objective-C实现BMP图像旋转180度(附完整源码)
查看>>
Objective-C实现bogo sort排序算法(附完整源码)
查看>>
Objective-C实现boruvka博鲁夫卡算法(附完整源码)
查看>>
Objective-C实现Boyer-Moore字符串搜索算法(附完整源码)
查看>>
Objective-C实现BP误差逆传播算法(附完整源码)
查看>>
Objective-C实现breadth First Search广度优先搜索算法(附完整源码))
查看>>
Objective-C实现BreadthFirstSearch广度优先搜索算法(附完整源码)
查看>>
Objective-C实现BreadthFirstShortestPath广度优先最短路径算法(附完整源码)
查看>>
Objective-C实现bubble sort冒泡排序算法(附完整源码)
查看>>
Objective-C实现bucket sort桶排序算法(附完整源码)
查看>>
Objective-C实现Burke 抖动算法(附完整源码)
查看>>
Objective-C实现Burrows-Wheeler 算法(附完整源码)
查看>>
Objective-C实现CaesarsCiphe凯撒密码算法(附完整源码)
查看>>
Objective-C实现calloc函数功能(附完整源码)
查看>>
Objective-C实现canny边缘检测算法(附完整源码)
查看>>
Objective-C实现cartesianProduct笛卡尔乘积算法(附完整源码)
查看>>