本文实例为大家分享了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; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
SpringBoot引用阿里easyexcel,Excel导出返回浏览器下载
HashMap、Hashtable、ConcurrentHashMap三者间的异同
解决RecycleView 中Item包含Edittext时,滑动view复用导致数据错乱的问题
多线程、同步工作原理、死锁案例、Lock接口、线程的生命周期的讲解及实现
网友评论