Skip to main content
joe_s66
Participant
January 24, 2018
Question

Removing seconds from XMPDateTime

  • January 24, 2018
  • 2 replies
  • 706 views

I'm trying to build a script in ExtendScript Toolkit CC that will modify the date metadata for files in Bridge. I'm using "var d = new XMPDateTime(new Date())" to get the full date value. How can I removed the seconds in the value and get this value instead --> YYYY MM DD HM. I've searched the Adobe site and forums and could not find an answer.

This topic has been closed for replies.

2 replies

Pedro Cortez Marques
Legend
February 5, 2018

You can use RegExp after convert the XMPDateTime to a string:

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var d = new XMPDateTime(new Date())

var result = d.toString().match(/\d{4}\-\d{2}\-\d{2}\T\d{2}\:\d{2}/).toString().replace(/\-|\T|\:/g,' ')

$.writeln(result);

SuperMerlin
Inspiring
February 6, 2018

I think the OP requires a new XMPDateTime to set the date Pedro, so this would fail.

We may never know as the OP has not responded.

SuperMerlin
Inspiring
January 24, 2018

Here is an example for ESTK run with target Bridge..

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var now = new Date();

$.writeln(now);

var seconds = now.getSeconds();

var mSeconds = now.getMilliseconds();

now = now.getTime() - ((seconds * 1000)+mSeconds);

$.writeln(new Date(now));

$.writeln(new XMPDateTime(new Date(now)));