2 changed files with 48 additions and 1 deletions
@ -0,0 +1,45 @@ |
|||||
|
package cn.chjyj.szwh.utils; |
||||
|
|
||||
|
import java.text.ParseException; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 日期时间工具 |
||||
|
*/ |
||||
|
public class DateUtils { |
||||
|
/** |
||||
|
* 时间转换成时间戳,参数和返回值都是字符串 |
||||
|
* @param s |
||||
|
* @return res |
||||
|
* @throws ParseException |
||||
|
*/ |
||||
|
public static long dateToStamp(String s) { |
||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
|
try { |
||||
|
Date date = simpleDateFormat.parse(s); |
||||
|
long ts = date.getTime(); |
||||
|
return ts; |
||||
|
}catch (ParseException ex){ |
||||
|
ex.printStackTrace(); |
||||
|
} |
||||
|
return 0l; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 将时间戳转换为时间,参数和返回值都是字符串 |
||||
|
* |
||||
|
* @param s |
||||
|
* @return res |
||||
|
*/ |
||||
|
public static String stampToDate(String s) { |
||||
|
String res; |
||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
|
long lt = new Long(s); |
||||
|
Date date = new Date(lt); |
||||
|
res = simpleDateFormat.format(date); |
||||
|
return res; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue