-->

Changing date format in Pentaho using javascriptin

2019-07-20 16:00发布

问题:

I have an input excel sheet which has a field "fail_date". I want to change the format to dd.MM.yyyy HH:mm:ss. I am doing this in javascript shown below.

var temp = fail_date.getDate();
str2date(temp,"dd.MM.yyyy HH:mm:ss");

But I get the below error when i run

2015/05/07 17:48:01 - Modified Java Script Value 2 2 2.0 - ERROR (version 4.4.0-stable, build 17588 from 2012-11-21 16.02.21 by buildguy) : Could not apply the given format dd.MM.yyyy on the string for Thu Jan 01 11:05:50 IST 1970 : Format.parseObject(String) failed (script#5)

script#5 points to str2date(temp,"dd.MM.yyyy HH:mm:ss"); . Please help to solve this issue.

回答1:

the variable temp is setted as date type object, but when you apply the str2date function, this function expects to be temp as string.

So this is how your code should be:

var temp = fail_date.getDate();
temp = date2str(temp,"dd.MM.yyyy HH:mm:ss");

remember now temp is a string type