标签:style color os io for ar 时间 new
/**
* 将长时间格式字符串转换为字符串 yyyy-MM-dd HH:mm:ss
* @return
*/
public static String longToStrng()
{
String time = "1256006105375";// long型转换成的字符串
Date date = new Date(Long.parseLong(time.trim()));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(date);
System.out.println("TIME:::" + dateString);
return dateString;
}
/**
* 将长时间格式字符串转换为字符串 yyyy-MM-dd HH:mm:ss
* * @return
*/
public static String longToStrng() {
String time = "1256006105375";// long型转换成的字符串
Date date = new Date(Long.parseLong(time.trim()));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(date);
System.out.println("TIME:::" + dateString);
return dateString;
}
/**
* 将yyyy-MM-dd HH:mm:ss 时间格式字符串转化成时间
* @return
*/
public static Date StringToDate() {
String time = "2009-10-21 10:35:05";// 时间格式的字符串
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date s = null;
try {
s = formatter.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("TIME:::" + s);
return s;
}
/**
* 将yyyy-MM-dd HH:mm:ss 时间格式字符串转化成时间
* @return
*/
public static Date StringToDate() {
String time = "2009-10-21 10:35:05";// 时间格式的字符串
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date s = null;
try {
s = formatter.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("TIME:::" + s);
return s;
}
/**
* 获取现在时间
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
System.out.println("TIME:::" + dateString);
return dateString;
}
/**
* 获取现在时间
* * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
System.out.println("TIME:::" + dateString);
return dateString;
}
/**
* 获取时间 小时:分;秒 HH:mm:ss
* * @return
*/
public static String getTimeShort() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date currentTime = new Date();
String dateString = formatter.format(currentTime);
System.out.println("TIME:::"+dateString);
return dateString;
}
/**
* 获取时间 小时:分;秒 HH:mm:ss
* * @return
*/
public static String getTimeShort() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date currentTime = new Date();
String dateString = formatter.format(currentTime);
System.out.println("TIME:::" + dateString);
return dateString;
}
/**
* 将20090402103531 转换成 yyyy-MM-dd HH:mm:ss形式输出
* * @return
*/
public static String strToDatestr() {
String ssss = "20090402103531";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String sss = null;
try {
sss = sdf2.format(sdf.parse(ssss));
System.out.println("result" + sss);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sss;
}
标签:style color os io for ar 时间 new
原文地址:http://www.cnblogs.com/zhaojinhui/p/3928588.html