Java 需要在 Talend Studio 中获取当前日期时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30102527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need to Get the current DateTime in the Talend Studio?
提问by Rajesh kannan
I am working the Talend studio tool for data migration. Now I want to set the Current DateTime in the Date field.
I get the DateTime from this code TalendDate.getDate("yyyy-MM-dd HH:mm:ss")
but it returns String type data. But I need Date
type to insert.Is there any String to date (Sample insert is like this:1999-12-13 16:14:48
) conversion is in the Talend Studio.
我正在使用 Talend Studio 工具进行数据迁移。现在我想在日期字段中设置当前日期时间。我从这段代码中得到 DateTime,TalendDate.getDate("yyyy-MM-dd HH:mm:ss")
但它返回 String 类型的数据。但我需要Date
插入类型。迄今为止是否有任何字符串(示例插入是这样的:)1999-12-13 16:14:48
转换在 Talend Studio 中。
采纳答案by Jordi Castilla
You can use routine function TalendDate.parseDate
to convert a String
to a Date
.
您可以使用例程函数TalendDate.parseDate
将 a 转换String
为 a Date
。
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", yourStringData);
If you want the current datetime:
如果你想要当前的日期时间:
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"));
But this makes no sense.
但这毫无意义。
Parsedate 函数准备接收字符串并将其转换为Date
Date
对象。Date
Date
对象有它自己的格式,所以你不必关心如何存储,you need to change the Date
format in the moment you show it, but not when you store it您需要在显示时更改Date
格式,而不是在存储时更改格式:// this will produce a correct Date Object to store in your Date field
Date currentDate = TalendDate.getCurrentDate();
When you need to show/print it use SimpleDateFormat
for example if you want to show 2015-07-05 16:00:00 you must do like this:
当您需要显示/打印它时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 ));
回答by kavi temre
its very simple with the use of DateFormat in java
在java中使用DateFormat非常简单
public static void convert(String inputDate) throws ParseException {
DateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
Date d = format.parse(inputDate); // example 1999-12-13 16:14:48
System.out.println(d);
}