Hi,
I have a JavaScript Problem with Date fields.
I have defined a attribute BUILD_DATE as date, and try to change it from JavaScript, it always becomes 12/31/1969 (day before JavaTime)
I appreciate any help,
Thanks,
Anders
Here is the code:
/**********************************************
* Print current BUILD_DATE value set through GUI
**********************************************/
println("Date: " + item.BUILD_DATE);
//Output: Tue Jan 13 2015 00:00:00 GMT-0500 (EST)
/**********************************************
* I set a string to the same date
**********************************************/
var strDate = "Tue Jan 13 2015 00:00:00 GMT-0500 (EST)";
/**********************************************
* Create a new Date
* NOTE: This becomes parsed differently, but is ok java date
**********************************************/
var dateBuildDate = new java.util.Date(strDate);
println("Date: "+ dateBuildDate);
//Output: Tue Jan 13 00:00:00 EST 2015
/**********************************************
* Set the new BUILD_DATE
**********************************************/
item.BUILD_DATE = dateBuildDate;
/**********************************************
* Print current BUILD_DATE value
* NOTE: Not good, now BUILD_DATE is one day before java time.
**********************************************/
println("Date: " + item.BUILD_DATE);
//Output: Wed Dec 31 1969 19:00:00 GMT-0500 (EST)
/******************************************
* EOF / Exit
******************************************/
Solved! Go to Solution.
Solved by jared.sund. Go to Solution.
Hello Anders,
You've used a new date function for Java, and not JavaScript. Change your new date function to javascript and all will be good.
Java New Date Notation:
/********************************************** var dateBuildDate = new java.util.Date(strDate);
Should be: JavaScript New Date Notation
var dateBuildDate = new Date(strDate);
Here's a couple good references for working with JavaScript dates:
http://www.w3schools.com/jsref/jsref_obj_date.asp
http://www.evotech.net/blog/2007/07/javascript-date-object/
Also, see UNIX time for why you're seeing 12/31/1969: http://en.wikipedia.org/wiki/Unix_time