Jor*_*lla 14
您可以使用例程函数TalendDate.parseDate
将a转换String
为a Date
.
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", yourStringData);
Run Code Online (Sandbox Code Playgroud)
如果你想要当前的日期时间:
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"));
Run Code Online (Sandbox Code Playgroud)
Date
对象.Date
对象具有自己的格式,因此您不必关心如何存储,您需要在显示时更改Date
格式,但不能在存储时更改格式:
// this will produce a correct Date Object to store in your Date field
Date currentDate = TalendDate.getCurrentDate();
Run Code Online (Sandbox Code Playgroud)
当您需要显示/打印它时SimpleDateFormat
,例如,如果您想要显示2015-07-05 16:00:00,您必须这样做:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss);
System.out.println("My date formatted is: " + sdf.format(currentDate ));
Run Code Online (Sandbox Code Playgroud)