Java字符串与日期的相互转换

1.字符串转日期

字符串的格式与日期的格式一定要对应,并且字符串格式可以比日期格式多,但不能少,数字大小不自动计算日期。其中需要主要大小写

年yyyy 月MM 日dd 时HH 分mm 秒ss 毫秒SS

        String str = "2018/12/32";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date strDate = simpleDateFormat.parse(str);
System.out.println(strDate); output:
Tue Jan 01 00:00:00 CST 2019

2.日期转字符串

        Date date = new Date();
String dateStr = simpleDateFormat.format(date);
System.out.println(dateStr);

  

Java字符串与日期互转的更多相关文章

  1. JAVA字符串转日期或日期转字符串【转】

    JAVA字符串转日期或日期转字符串[转] 文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: S ...

  2. android JAVA字符串转日期或日期转字符串(转)

    用法: SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " ); 这一行最重要,它确立了转换的 ...

  3. JAVA字符串转日期或日期转字

    文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进来! 用法:    SimpleDateFormat sdf ...

  4. JAVA字符串转日期或日期转字符串

    文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: SimpleDateFormat sdf = ...

  5. (转)Java字符串转日期或日期转字符串

    文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: SimpleDateFormat sdf = ...

  6. java 字符串转日期格式

    /** * 字符串转日期格式 * */ public static Date date(String date_str) { try { Calendar zcal = Calendar.getIns ...

  7. Java字符串转换为日期和时间比较大小

    字符串转换为时间: String data = "2014/7/11"; SimpleDateFormat dfs = new SimpleDateFormat("yyy ...

  8. Java - 字符串和Unicode互转 - 解析小米pm.min.js

    小米JS地址: http://p.www.xiaomi.com/zt/20130313/huodong/pm.min.js 上面这个JS是小米抢手机页面的代码.和抢手机有直接关联.. 虽然我3次都没抢 ...

  9. java字符串大小写字母互改

    import java.util.Scanner; public class Test { /** * 测试数据 * * @param args */ public static void main( ...

随机推荐

  1. Golang格式化小结

    Golang的格式化使用了与c.python等语言类似的风格,但是更加丰富和通用.格式化函数在fmt包中,如:fmt.Printf,fmt.Fprintf,fmt.Sprintf,fmt.Printl ...

  2. BZOJ5418:[NOI2018]屠龙勇士(exCRT,exgcd,set)

    Description Input Output Sample Input 23 33 5 74 6 107 3 91 9 10003 23 5 64 8 71 1 11 1 Sample Outpu ...

  3. ethereumjs/ethereumjs-common-3-test

    查看test能够让你更好滴了解其API文档的使用 ethereumjs-common/tests/chains.js const tape = require('tape') const Common ...

  4. robotframwork接口测试(五)—接口分层测试粗解

    个人小结,仅供参考. 接口测试很简单,但是很重要. 可以写代码,也可以用工具进行测试.工具说说就很多了,简单介绍一下我目前用过的几个能够测试接口的工具, Burpsuite:这类偏请求攻击类软件 Fi ...

  5. pip问题解决方案

    错误信息:usr/bin/pip: No such file or directory 解决办法(一共四步,按照下面的步骤来从1到4,最后你会发现问题都解决了): 1.which pip /usr/l ...

  6. NYOJ-171 聪明的kk 填表法 普通dp

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=171 聪明的kk 时间限制:1000 ms  |  内存限制:65535 KB 难 ...

  7. python通过cx_oracle操作数据库过程简单记录

    1.环境配置 环境配置过程中,需要关注软件版本是否一致,主要包括:oracle客户端版本.cx_oracle版本.python版本: 2.操作记录 (1)验证环境是否正常:(无报错即为正常) impo ...

  8. 理解C++类的继承方式(小白)

    基类里的 public(大人) protect(青年) private(小孩) 在通过继承时  继承方式public(我是大人咯) protect(我是青少年) private(我系小孩纸啦) &qu ...

  9. LaTeX宏包TikZ绘图示例——Go语言起源图

      本例所绘图形选自<Go语言程序设计>(作者:Alan A. A. Donovan与Brian W. Kernighan)一书的前言部分. 完整代码 \documentclass{art ...

  10. spring-data-jpa快速入门(一)——整合阿里Druid

    一.概述 官网:https://projects.spring.io/spring-data-jpa/ 1.什么是spring-data-jpa Spring Data JPA, part of th ...