请教WINDOWS怎么批量转换时间戳

如题所述

第1个回答  2016-12-14
  时间戳就是如1377216000000 这种格式,在mysql数据库中会经常用到把时间转换成时间戳或把时间戳转换成日期格式了,下面是时间戳操作转换方法:
  一、原理
  时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算
  如: 2013年08月23日 转化后是 1377216000000
  二、步骤
  1、创建 DateUtilsl类。
  代码如下:
  importjava.text.ParseException;
  importjava.text.SimpleDateFormat;
  importjava.util.Date;  
  /*
  * @author Msquirrel
  */
  public class DateUtils {  
  privateSimpleDateFormat sf = null;
  /*获取系统时间 格式为:"yyyy/MM/dd "*/
  public static String getCurrentDate() {
  Date d = newDate();
  sf = newSimpleDateFormat("yyyy年MM月dd日");
  returnsf.format(d);
  }  
  /*时间戳转换成字符窜*/
  public static String getDateToString(long time) {
  Date d = newDate(time);
  sf = newSimpleDateFormat("yyyy年MM月dd日");
  returnsf.format(d);
  }  
  /*将字符串转为时间戳*/
  public static long getStringToDate(String time) {
  sdf = newSimpleDateFormat("yyyy年MM月dd日");
  Date date = newDate();
  try{
  date = sdf.parse(time);
  } catch(ParseException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  returndate.getTime();
  }
  2、在对应使用的地方调用。
  代码如下:
  DateUtils.getCurrentDate(); //获取系统当前时间  
  DateUtils.getDateToString(时间戳); //时间戳转为时间格式  
  DateUtils.getStringToDate("时间格式");//时间格式转为时间戳.
相似回答