- public static String timeStamp2Date(String seconds,String format) {
- if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
- return "";
- }
- if(format == null || format.isEmpty()) format = "yyyy-MM-dd HH:mm:ss";
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- return sdf.format(new Date(Long.valueOf(seconds+"000")));
- }
-
- public static String date2TimeStamp(String date_str,String format){
- try {
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- return String.valueOf(sdf.parse(date_str).getTime()/1000);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "";
- }
-
-
- public static String timeStamp(){
- long time = System.currentTimeMillis();
- String t = String.valueOf(time/1000);
- return t;
- }
-
-
-
-
-
- public static void main(String[] args) {
- String timeStamp = timeStamp();
- System.out.println("timeStamp="+timeStamp);
-
- String date = timeStamp2Date(timeStamp, "yyyy-MM-dd HH:mm:ss");
- System.out.println("date="+date);
-
- String timeStamp2 = date2TimeStamp(date, "yyyy-MM-dd HH:mm:ss");
- System.out.println(timeStamp2);
- }
posted @
2016-09-08 09:22
飘飘雪
阅读(
46269)
评论()
编辑
收藏
举报