I just want the date to show up like so:
Saturday, May 26, 2012 at 10:42 PM
Here's my code so far:
Calendar calendar = Calendar.getInstance(); String theDate = calendar.get(Calendar.MONTH) + " " + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.YEAR); lastclick.setText(getString(R.string.lastclick) + " " + theDate); This shows the numbers of the month, day, and year, but there's got to be a better way of doing this? Isn't there some simple way of doing this like using PHP's date() function?
The default date format shows as YYYY-MM-DD.
yyyy-MM-dd — Example: 2013-06-23.
Ranges. A simple year–year range is written using an en dash ( – , – or {{ndash}} ), not an em dash, hyphen, or slash; this dash is unspaced (that is, with no space on either side); and the end year is usually given in full: 1881–1882; 1881–1886 (not 1881–86); 1881–1992 (not 1881–92)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With