I am using the following bit of code to extract the XMP CreateDate from a photoshop image.
var md = thumb.metadata;
md.namespace = "http://ns.adobe.com/xap/1.0/";
mInfo = md.CreateDate + "\n" + md.AuthorsPosition;
Unfortunately, it returns a string "2008-01-13T00:52:18-6:00"
How do I coerce this to a specific date format i.e.: "01/13/2008, 1:52:18 PM"
Can I do it in the initial query, or is there a built in method for converting the returned value?
There are a few ways of doing it, one of the more simpler methods is to use string manipulation, as an example...
var thumb = app.document.selections; var md = thumb.synchronousMetadata; md.namespace = "http://ns.adobe.com/xap/1.0/"; var d = md.CreateDate; var db = d.match(/\d+/g); var dateIs = db+"/"+db+"/"+db+", "+db+":"+db+":"+db+" "; var amOrPm = "AM"; if (Number(db) > 11) amOrPm = "PM"; dateIs += amOrPm; alert (dateIs );
Works perfectly. Thanks for the code.
You'd think that there would be a more sophisticated method than resorting to string manipulation.
The unix shell and any other programming language I have used have had the ability to do simple stuff like this for 20 years at least.