javascript 想要在pentaho中将String数据类型转换为Date数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29911473/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:17:09  来源:igfitidea点击:

Want to convert String data type into Date data type in pentaho

javascriptpentahopentaho-data-integration

提问by Mudi

I have a string which has a date in this format: n_date=2014-04-20

我有一个字符串,它有这种格式的日期: n_date=2014-04-20

I want to convert it into date data type

我想把它转换成日期数据类型

var Final_date = str2date(n_date,"yyyy-MM-dd");

but I get an error.

但我收到一个错误。

I'm do this in pentaho

我在做这个 pentaho

回答by nsousa

You don't need a Java script step to do that. It's much easier and faster to use a calculator step or a select values step instead:

您不需要 Java 脚本步骤来执行此操作。使用计算器步骤或选择值步骤更容易、更快捷:

1) Calculator step: Create a new field, Final_date as a Copy of field A; on Field A put the name of your input string; Data type is date and on Conversion mask choose the yyyy-MM-dd format (you don't have to pick one from the dropdown menu, you can write your own);

1)计算器步骤:创建一个新字段,Final_date作为字段A的副本;在字段 A 上输入输入字符串的名称;数据类型是日期,在转换掩码上选择 yyyy-MM-dd 格式(您不必从下拉菜单中选择一种,您可以自己编写);

2) Select values: on the Metadata panel, choose your input field and Date as the data type; as above, fill in the date format your data comes in.

2) 选择值:在元数据面板上,选择您的输入字段和日期作为数据类型;如上所述,填写您的数据输入的日期格式。

The difference between 1) and 2) is that in the 1st case you get a new field of the Date type, whereas in the 2nd case you change the data type of the input field.

1) 和 2) 之间的区别在于,在第一种情况下,您会获得一个 Date 类型的新字段,而在第二种情况下,您会更改输入字段的数据类型。