zoukankan      html  css  js  c++  java
  • 13位时间戳与格式化日期之间的转换实现

    1 import java.text.ParseException;
     2 import java.text.SimpleDateFormat;
     3 import java.util.Date;
     4 
     5 public class DateUtil {
     6     
     7     private static SimpleDateFormat sf = null;
     8     
     9     /**
    10      * 获取系统时间 
    11      */
    12     public static String getCurrentDate() {
    13         Date d = new Date();
    14          sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    15         return sf.format(d);
    16     }
    17                                       
    18     /**
    19      * 时间戳转换成字符串
    20      */
    21     public static String getDateToString(long time) {
    22         Date d = new Date(time);
    23         sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    24         return sf.format(d);
    25     }
    26 
    27     /**
    28      * 将字符串转为时间戳
    29      */
    30     public static long getStringToDate(String time) {
    31         sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    32         Date date = new Date();
    33         try{
    34             date = sf.parse(time);
    35         } catch(ParseException e) {
    36             e.printStackTrace();
    37         }
    38         return date.getTime();
    39     }
    40     
    41     /**
    42      * 直接获取时间戳
    43      */
    44     public static String getTimeStamp() {
    45         String currentDate = getCurrentDate();
    46         sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    47         Date date = new Date();
    48         try{
    49             date = sf.parse(currentDate);
    50         } catch(ParseException e) {
    51             e.printStackTrace();
    52         }
    53         return String.valueOf(date.getTime());
    54     }
    55     
    56 }
     
    

      

  • 相关阅读:
    MS SQL Server2012中的TRY_CONVERT函数
    MS SQL Server2012中的CONCAT函数
    查询数据库大小
    显示数据与存储方式
    Windows 8 安装之后怎样更改产品码
    IIS SubStatus Codes
    MS SQL Server Quarter Function
    程序中处理一对多的数据
    找出字符串中所有数字
    BOOTMGR is missing
  • 原文地址:https://www.cnblogs.com/wangcp-2014/p/11458573.html
Copyright © 2011-2022 走看看