Tutorial by Examples

DateUtils.formatDateTime() allows you to supply a time, and based on the flags you provide, it creates a localized datetime string. The flags allow you to specify whether to include specific elements (like the weekday). Date date = new Date(); String localizedDate = DateUtils.formatDateTime(contex...
Format a date: Date date = new Date(); DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); String localizedDate = df.format(date) Format a date and time. Date is in short format, time is in long format: Date date = new Date(); DateFormat df = DateFormat.getDateTimeInstance(DateFor...
Date date = new Date(); df = new SimpleDateFormat("HH:mm", Locale.US); String localizedDate = df.format(date) Commonly used patterns: HH: hour (0-23) hh: hour (1-12) a: AM/PM marker mm: minute (0-59) ss: second dd: day in month (1-31) MM: month yyyy: year

Page 1 of 1