Skip to main content
joe_s66
Participant
Jan 24, 2018 3:42 PM UTC
Question

Removing seconds from XMPDateTime

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Pedro Cortez Marques
Legend
Feb 5, 2018 10:04 PM UTC

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);

Translate
SuperMerlin
Inspiring
Feb 6, 2018 8:24 AM UTC

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.

Translate
SuperMerlin
Inspiring
Jan 24, 2018 9:04 PM UTC

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)));

Translate