Created
June 11, 2010 15:27
-
-
Save statonjr/434629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/macruby | |
# Need the AddressBook framework | |
framework 'AddressBook' | |
# Singleton | |
ab = ABAddressBook.sharedAddressBook | |
# me is the ABRecord of the current logged in user | |
# valueForProperty() is the KVO method to get the constant | |
# note the uppercase K. In Obj-C, the property is kABCreationDateProperty | |
creation_date = ab.me.valueForProperty(KABCreationDateProperty) # => NSDate object | |
# NSDate objects are not converted to Ruby Date objects | |
# Obj-C uses formatters to create strings from dates | |
date_formatter = NSDateFormatter.alloc.init | |
# Another constant | |
date_formatter.setDateStyle(NSDateFormatterMediumStyle) | |
# Here's our string | |
creation_date_string = date_formatter.stringFromDate(creation_date) | |
puts creation_date_string # => 'Jun 11, 2010' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment