Skip navigation
JamesHaney
Currently Being Moderated

Coercing string to date

May 7, 2013 8:28 AM

Tags: #bridge #date #coerce

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?

 

- James

 
Replies
  • Currently Being Moderated
    May 7, 2013 10:55 AM   in reply to JamesHaney

    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[0];
    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[1]+"/"+db[2]+"/"+db[0]+", "+db[3]+":"+db[4]+":"+db[5]+" ";
    var amOrPm = "AM";
    if (Number(db[3]) > 11) amOrPm = "PM";
    dateIs += amOrPm;
    alert (dateIs );
    
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points