Skip to content

Instantly share code, notes, and snippets.

@W3BGUY
Last active November 16, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W3BGUY/f711244e2b2b40182004eac2d635e36e to your computer and use it in GitHub Desktop.
Save W3BGUY/f711244e2b2b40182004eac2d635e36e to your computer and use it in GitHub Desktop.
NetSuite - Convert Date Object into NetSuite usable Datetime Format
// 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