How to get date format using vro

get date
var date = new Date(),
  yy=date.getFullYear().toString().substr(2,2);
  mm=(date.getMonth() < 10 ? "0" : "") + (date.getMonth()+1);
  dd=(date.getDate() < 10 ? "0" : "") + date.getDate();
  HH=(date.getHours() < 10 ? "0" : "") + date.getHours();
  MM=(date.getMinutes() < 10 ? "0" : "") + date.getMinutes();

Example:
var myTimestamp = System.getCurrentTime();
var myDate = new Date();
myDate.setTime(myTimestamp);
System.log("getYear from DateObject: "+(myDate.getYear()+1900));
System.log(System.formatDate(myDate, "YYYY-MM-dd HH:mm:ss"));

Add Days:
timerDate = new Date();
System.log( "Current date : '" + timerDate + "'" );
timerDate.setTime( timerDate.getTime() + (86400 * 1000) );

System.log( "Timer will expire at '" + timerDate + "'" );


The preceding example JavaScript function defines a Date object that obtains the current date and time by using the getTime method and adds 86,400,000 milliseconds, or 24 hours.

Comments

Popular posts from this blog

Creating Snapshots for Unmanaged VMs in Aria Automation (vRealize Automation)

Bulk import security policies into Palo Alto Networks firewalls

Automating Tag Creation & Assignment to VMs with vRA + vRO