Formatting a calendar date

Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm a");
System.out.println(format.format(calendar.getTime()));

Running the above code outputs the current time (e.g., Saturday, May 26, 2012 at 11:03 PM).

See the Android documentation for SimpleDateFormat for more information.

The format specification of SimpleDateFormat is similar to that of PHP’s date function:

echo date("l, M j, Y \a\\t g:i A");

You’re right. Compared to the Java code, the PHP code is much more succinct.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)