David Golding



Formatting Dates in Cappuccino with CPDateHelper

By David Golding | Print This Post Print This Post

I missed being able to format dates like I do in PHP and with a current Cappuccino app I’m working on, I couldn’t help build a date formatting helper. I’ve posted it as an open source class on GitHub and invite your contributions, feedback, or use.

Using this class is simple. Just download and place the CPDateHelper.j file in your Cappuccino app directory. Then include the class using:

1
@import "CPDateHelper.j"

Anywhere in your Cappuccino app, just provide CPDateHelper with a date string and a formatting string and it will return a formatted date string. For example:

1
var formattedDateString = [CPDateHelper date:@"Wed Aug 5 2009 13:00:00" withFormat:@"D M jS Y g:i A"];

In this example, formattedDateString will contain:

1
Wed Aug 5th 2009 1:00 PM

CPDateHelper also returns the formatted date string as a CPString object, so you can use CPString methods on it right out of the box.

Again, jump on over to the GitHub project to download the source or

Download CPDateHelper.zip


Comments

No Responses to “Formatting Dates in Cappuccino with CPDateHelper”



Submit Comment


Beginning CakePHP: From Novice to Professional by David Golding

Other Blogs

David Golding

A blog about CakePHP, web design, and grad studies in religion. © 2008, D. Golding