• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: parsing Unix date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing Unix date


  • Subject: Re: parsing Unix date
  • From: Graff <email@hidden>
  • Date: Fri, 09 Jan 2004 13:59:07 -0500

Well, the easiest way is to simply format the date string in a way AppleScript can parse easily:
----------
set d to (do shell script "date '+%A, %B %e, %Y %T'")
---> "Friday, January 9, 2004 13:07:10"
date d
---> date "Friday, January 9, 2004 1:07:10 PM"
----------

Now if you are handed an arbitrary date string and you don't have control over the format then things can get a bit tougher. Obviously AppleScript does a decent job of parsing date strings but it can't handle every case. Here's a way of parsing out just the time portion through the use of the command-line tool awk.
--------
set d to (do shell script "date")
---> "Fri Jan 9 13:53:33 EST 2004"
set g to do shell script "echo " & d & "|awk 'BEGIN { RS = \" \" } /.*:.*:.*/ { print }'"
---> "13:53: 33"
set theDate to date d
---> date "Friday, January 9, 2004 9:13: 53 AM"
set time of theDate to time of date g
---> 50013
display dialog (date string of theDate) & return & (time string of theDate)
---> "Friday, January 9, 2004"
---> "1:53:33"
--------

You could probably do the same thing with any OSAX that lets you use regular expressions.

- Ken

On Jan 9, 2004, at 9:48 AM, Michael Grant wrote:

set d to (do shell script "date") --> "Fri Jan 9 01:00:02 CST 2004"
date d --> date "Friday, January 9, 2004 9:01:00 AM"

What's wrong with this picture?

More to the point, how can I transform a Unix date to an AppleScript date more accurately?
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: parsing Unix date
      • From: Paul Berkowitz <email@hidden>
References: 
 >parsing Unix date (From: Michael Grant <email@hidden>)

  • Prev by Date: Re: Safari windows
  • Next by Date: Re: Safari windows
  • Previous by thread: Re: parsing Unix date
  • Next by thread: Re: parsing Unix date
  • Index(es):
    • Date
    • Thread