简体   繁体   中英

Date format conversion from “yyyy-mm-dd” to “dd/mm/yyyy” in pentaho using javascript

I have a csv file where the date field has a format "yyyy-mm-dd" and I wish to convert it into "dd/mm/yyyy" using javascript. This is the javascript it found out from this reference

"could not apply the given format yyyy/mm/dd on the string for 2015-02-04 :Format.parseObject(String) failed(script#3)"

this is the javascript code I used

var dateObj = str2date(Date_of_joining, "yyyy/mm/dd");
 var newDate = date2str(dateObj, "dd/MM/yyyy");

I even tried using Select Value step and changed the meta data to date and specified the format to "dd/MM/yyyy" but still not working.How do I solve this

这是使用选择值步骤后得到的错误

The date you are parsing is not using slashes, but you're defining slashes when you parse it. Switch your slashes to dashes:

var dateObj = str2date(Date_of_joining, "yyyy-mm-dd");
var newDate = date2str(dateObj, "dd/MM/yyyy");

Here we go:

Try to reconstruct DateTime string as like this:

var dateObj = new Date(Date_of_joining);
var newDate = new Date(dateObj );
var formattedString = [newDate.Date(),newDate.Month()+1, newDate.getFullYear()].join("/");
alert(formattedString );

Hope it helps;)

function convertLinuxDate(linux_date) {
    //linux_date = "2001-01-02"
    var arrDate = linux_date.split("-");
    return arrDate[1] + "/" +arrDate[2] + "/" + arrDate[0];
}
//returns 01/02/2001

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM