Java时间类型转换方法实例教程.一、取得long类型的时间
view plaincopy to clipboardprint?
Java代码





- long m = System.currentTimeMillis();
long m = System.currentTimeMillis();
此时可以得到当前系统时间以前的某个时间,并将其转化为制定类型的String类型: view plaincopy to clipboardprint?
Java代码





- public static String getDate(int n){
- long m = System.currentTimeMillis();
- long datet = m – n * 60 * 1000;
- String ss = new SimpleDateFormat(“yyyy-MM-dd HH:mm”).format(datet);
- System.out.println(“datet” + datet);
- return ss;
- }
public static String getDate(int n){ long m = System.currentTimeMillis(); long datet = m - n * 60 * 1000; String ss = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(datet); System.out.println("datet" + datet); return ss; }
二、取得String类型时间,并将其按指定类型输出:
view plaincopy to clipboardprint?
Java代码





- String date = new SimpleDateFormat(“yyyy-MM-dd HH:mm-HH:mm”).format(Calendar.getInstance().getTime());
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm-HH:mm").format(Calendar.getInstance().getTime());
三、给定string类型的时间,求其以前的某个时间:
view plaincopy to clipboardprint?
Java代码





- public static String getBefore15Time(String date){
- DateFormat f = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
- Date d = new Date();
- try {
- d = f.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- long Time=(d.getTime());
- long datet = Time – 15 * 60 * 1000;
- String ss = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”).format(datet);
- return ss;
- }
- http://alert008.iteye.com/blog/581305