Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JavaScript Date always becomes 12/31/1969

1 REPLY 1
SOLVED
Reply
Message 1 of 2
anders.broddstedt
5731 Views, 1 Reply

JavaScript Date always becomes 12/31/1969

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
******************************************/

1 REPLY 1
Message 2 of 2

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

 

Jared Sund
Sr. Product Line Manager, Product Lifecycle Management
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report