当前位置: 移动技术网 > IT编程>开发语言>Java > java DateUtil工具类时间戳类型转换详解

java DateUtil工具类时间戳类型转换详解

2019年07月19日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了dateutil工具类时间戳类型转换的具体代码,供大家参考,具体内容如下

package com.sinosoft.media.sms.util; 
import java.text.parseexception; 
import java.text.simpledateformat; 
import java.util.date; 
public class dateutil { 
  
 //当前时间 
 //public static date date_now=new date(); 
  
  
 /** 
 * 得到完整的时间戳,格式:yyyymmddhhmmsssss(年月日时分秒毫秒) 
 * @return 完整的时间戳 
 */ 
 public static string getfulltimestamp(){ 
 return new simpledateformat("yyyymmddhhmmsssss").format(new date()) ; 
 } 
  
 /** 
 * 得到简单的时间戳,格式:yyyymmdd(年月日) 
 * @return 简单的时间戳 
 */ 
 public static string getsimpletimestamp(){ 
 return new simpledateformat("yyyymmdd").format(new date()) ; 
 } 
  
 /** 
 * 根据指定的格式得到时间戳 
 * @param pattern 指定的格式 
 * @return 指定格式的时间戳 
 */ 
 public static string gettimestampbypattern(string pattern){ 
 return new simpledateformat(pattern).format(new date()) ; 
 } 
  
 /** 
 * 得到当前日期格式化后的字符串,格式:yyyy-mm-dd(年-月-日) 
 * @return 当前日期格式化后的字符串 
 */ 
 public static string gettodaystr(){ 
 return new simpledateformat("yyyy-mm-dd").format(new date()) ; 
 } 
  
 /** 
 * 时间戳,格式:yyyy-mm-dd hh:mm:ss(年-月-日 时:分:秒) 
 * @return 简单的时间戳 
 */ 
 public static string getdatetimestamp(date date){ 
 return new simpledateformat("yyyy-mm-dd hh:mm:ss").format(date) ; 
 } 
  
 public static date getdatebystring(string str){ 
 simpledateformat sim=new simpledateformat("yyyy-mm-dd hh:mm:ss"); 
 date datetime = null; 
 try { 
  datetime = sim.parse(str); 
 } catch (parseexception e) { 
  e.printstacktrace(); 
 } 
 return datetime; 
 } 
  
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网