admin管理员组

文章数量:1287169

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

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

Share Improve this question asked Apr 28, 2016 at 5:58 DeepeshDeepesh 8401 gold badge15 silver badges32 bronze badges 2
  • you may reconstruct dateTime string – Husni Salax Commented Apr 28, 2016 at 6:06
  • why do it in javascript? Just specify the right mask in your select values step. – Codek Commented Apr 28, 2016 at 13:29
Add a ment  | 

3 Answers 3

Reset to default 5

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");
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

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;)

本文标签: Date format conversion from quotyyyymmddquot to quotddmmyyyyquot in pentaho using javascriptStack Overflow