Last active
November 16, 2016 16:01
-
-
Save W3BGUY/f711244e2b2b40182004eac2d635e36e to your computer and use it in GitHub Desktop.
NetSuite - Convert Date Object into NetSuite usable Datetime Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to add leading zeros on date parts. | |
function zeroPad(num,len){ | |
var str=num.toString(); | |
while(str.length<len){str='0'+str;} | |
return str; | |
} | |
// function to format date object into NetSuite's mm/dd/yyyy HH:MM:SS format. | |
function formatNSDateTime(dateObj){ | |
if(dateObj){ | |
var nsFormatDateTime=(dateObj.getMonth()+1)+'/'+dateObj.getDate()+'/'+dateObj.getFullYear()+' '+addZeros(dateObj.getHours(),2)+':'+addZeros(dateObj.getMinutes(),2)+':'+addZeros(dateObj.getSeconds(),2); | |
return nsFormatDateTime; | |
} | |
return null; | |
} | |
// example usage | |
var thisDateTime=formatNSDateTime(new Date()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment