2016-02-26 59 views
0

我有一个数据库(不是SQL),其时间字段全部充满了本地时间。 而我有一个数据库(SQL)与时间字段在UTC。现在我想在这些数据库之间交换信息,但是如果我可以从本地时间转换为UTC,反之亦然,我只能意识到这一点。我如何在Talend中实现这一点?我如何将本地时间转换为UTC,反之亦然在Talend作业中

我知道当地时间数据库中的数据,是荷兰当地时间。 (GMT + 8北京时间(夏季)的(冬季))

Examples: 
23-10-2015 16:00 Local time => 23-10-2015 14:00 UTC (and vice versa) 
26-10-2015 16:00 Local time => 26-10-2015 15:00 UTC (and vice versa) 
+0

也许这可以帮助你。 http://stackoverflow.com/questions/16663990/casting-date-in-talend-data-integration – error505

+0

不幸的不是。 – PSVSupporter

回答

2

下面的截图有

tFixedFlowInput_1 - 定义一个模式与localDateTime(填充)和utcDateTime(无人居住)

tJavaRow_1 - 在localDateTime上执行中/欧洲到UTC时区对话并填充utcDateTime。这是唯一必不可少的部分。

tLogRow_1 - 显示结果

enter image description here

接下来,设置模式为tFixedFlowInput,并添加一些数据 enter image description here

enter image description here

下一页...设置的tJavaRow_1组件

tJavaRow_ 1高​​级设置/进口低于:

import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.TimeZone; 
import java.text.ParseException; 

tJavaRow_1基本设置(真正的代码)低于:

注意,try和catch块已被注释掉,从而引发异常和拓蓝招聘可以处理它们。

使用两个SimpleDateFormat实例,每个实例都与时区关联。 localDateTime通过源格式化程序进行分析。然后,使用目标格式化程序将日期转换为UTC并将其作为原始格式的字符串返回。从UTC回到本地是一个微不足道的变化。

String BASE_FORMAT = "dd-MM-yyyy HH:mm"; 
TimeZone utcTZ = TimeZone.getTimeZone("UTC"); 
TimeZone ceTZ = TimeZone.getTimeZone("Europe/Amsterdam"); 

SimpleDateFormat formatUTC = new SimpleDateFormat(BASE_FORMAT); 
formatUTC.setTimeZone(utcTZ); 

SimpleDateFormat formatCE = new SimpleDateFormat(BASE_FORMAT); 
formatCE.setTimeZone(ceTZ); 

output_row.localDateTime = input_row.localDateTime; 

// Commented out the try and catch, so the exception is thrown to Talend job 
//try { 
    Date dateTimeLocal = formatCE.parse(input_row.localDateTime); 
    output_row.utcDateTime = formatUTC.format(dateTimeLocal); 
//}  
//catch (ParseException pe) { 
// System.out.println(pe.getMessage()); 
//} 

接下来,tLogRow_1只显示流上的数据。以下是使用示例数据运行的示例。

enter image description here

+0

我尝试了,但我得到了多个错误 “导入java.util.TimeZone与另一个导入语句冲突” “类型TimeZone的方法getTimeZone(String)未定义” “类型中的方法setTimeZone(TimeZone) DateFormat不适用于参数(TimeZone)“ – PSVSupporter

+0

这适用于Talend 6.1.1和Java 1.8。你使用的是什么版本的Java?我今天晚些时候还可以提供一个链接来下载示例项目。 – dbh

+0

这两个旧版本。我会更新它们并重试。 – PSVSupporter

相关问题