/**
* 字符串转Date方法
* @param dateStr
* @param format 如yyyy-MM-dd HH:mm:ss等
* @return
* @throws Exception
*/
public static Date stringToDate(String dateStr,String format) throws Exception{
if(dateStr==null||"".equals(dateStr)){
throw new Exception("stringToDate:要转换的日期参数为空!");
}
Date date = null;
try{
SimpleDateFormat sdf = new SimpleDateFormat(format);
date = sdf.parse(dateStr);
}catch(Exception e){
e.printStackTrace();
} return date;
}
/**
* Date转字符串方法
* @param date
* @param format 如yyyy-MM-dd HH:mm:ss等
* @return
* @throws Exception
*/
public static String dateToString(Date date,String format) throws Exception{
if(date==null){
throw new Exception("dateToString:要转换的日期参数为空!");
}
String dateStr = "";
try{
SimpleDateFormat sdf = new SimpleDateFormat(format);
dateStr = sdf.format(date);
}catch(Exception e){
e.printStackTrace();
} return dateStr;
}

字符串和date之间的相互转换方法的更多相关文章

  1. 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换

    [源码下载] 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换 作者:webabcd 介绍速战速决 之 PHP ...

  2. Python3 字符串与hex之间的相互转换

    在字符串转换上,python2和python3是不同的,在查看一些python2的脚本时候,总是遇到字符串与hex之间之间的转换出现问题,记录一下解决方法. 1. 在Python2.7.x上,hex字 ...

  3. (转)golang获取当前时间、时间戳和时间字符串及它们之间的相互转换

    原文连接: https://blog.csdn.net/skh2015java/article/details/70051512 1.获取当前时间 currentTime:=time.Now() // ...

  4. php date之间的相互转换

    字符串转成date $str =date("Y-m-d H:i:s",strtotime("2011-12-12 14:23:01")); echo $str; ...

  5. python中字符串与列表之间的相互转换

    1.字符串>列表:split() a = 'my first python' b = a.split(" ") print(b)输出: 2.列表>字符串:join() ...

  6. [Swift]扩展UIColor:实现十六进制颜色字符串与UIColor之间的相互转换

    对[UIColor]进行扩展 import UIKit extension UIColor { // Hex String -> UIColor convenience init(hexStri ...

  7. Java的Map和Object之间的相互转换方法

    public staic Map<String, Object> objectToMap(Object obj) throws Exception { if(obj == null) re ...

  8. c#中jeson字符串和OBJECT对象的相互转换

    对于本问题   我用三步来分别说明实现过程 1.定义一个类---- 实现转换的具体方法 using System; using System.Collections.Generic; using Sy ...

  9. JS中实现JSON对象和JSON字符串之间的相互转换

    对于主流的浏览器(比如:firefox,chrome,opera,safari,ie8+),浏览器自己提供了JSON对象,其中的parse和stringify方法实现了JSON对象和JSON字符串之间 ...

随机推荐

  1. something about css locating.

    CSS position:static:默认属性,静态定位relative:相对定位,相对于父元素的定位,需要配合top,left,right,bottom,z-index等属性absolute:绝对 ...

  2. poj 1731 Orders

    http://poj.org/problem?id=1731 Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9 ...

  3. 数据库SQL CRUD

    1.删除表 drop  table +表名 2.修改表 alter  table+表名+ add(添加)+列名+ int(类型) alter  table+表名+ drop(删除)+column(列) ...

  4. php中时间戳和日期格式的转换

    一,PHP时间戳函数获取指定日期的unix时间戳 strtotime(”2009-1-22″) 示例如下: echo strtotime(”2009-1-22″) 结果:1232553600 说明:返 ...

  5. HDU 4900 NO ACM NO LIFE(概率+枚举+搜索)(2014 Multi-University Training Contest 4)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4900 Problem Description There is an old country and ...

  6. UVA 10498 Happiness(线性规划-单纯形)

    Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...

  7. 12---Net基础加强

    使用ShowDialog窗体之间的回传值: using System; using System.Collections.Generic; using System.ComponentModel; u ...

  8. js 获取select 中option 的个数

    //document.writeln(document.getElementById("sel").options.length); //document.writeln(docu ...

  9. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindow Overlayer 1

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindow Overlayer 1 ------------------------------------HALCON HWindow ...

  10. MapReduce之Writable相关类

    当要在进程间传递对象或持久化对象的时候,就需要序列化对象成字节流,反之当要将接收到或从磁盘读取的字节流转换为对象,就要进行反序列化.Writable是Hadoop的序列化格式,Hadoop定义了这样一 ...