try {
Calendar cal = Calendar.getInstance()//日期类
java.sql.Timestamp timestampnow = new java.sql.Timestamp(cal.getTimeInMillis())//转换成正常的日期格式
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
ParsePosition pos = new ParsePosition(0)
java.util.Date current = formatter.parse(date_str, pos)
timestampnow = new java.sql.Timestamp(current.getTime())
return timestampnow
}
catch (NullPointerException e) {
return null
}
}
java里时间类型转为String类型方法如下:import java.text.ParseException
import java.text.SimpleDateFormat
public class Dog {
public static void main(String[] args) {
String str = "2010-11-4 17:50:55.66"
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd")
try {
System.out.println(fmt.format(fmt.parse(str)))
} catch (ParseException e) {
e.printStackTrace()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)