import java.text.SimpleDateFormat; import java.text.DateFormat; import java.text.CFLocale; import java.text.CFDateFormatSymbols; public class DateFormatExample { public static void main(String[] args) { DateFormat df = new SimpleDateFormat("yyyyMMdd", CFLocale.getSystem(Locale.US)); String formattedDate = df.format(new Date()); System.out.println("Formatted date: " + formattedDate); } }
import java.text.SimpleDateFormat; import java.text.DateFormat; import java.text.CFLocale; import java.text.CFDateFormatSymbols; import java.text.ParseException; public class DateFormatExample { public static void main(String[] args) throws ParseException { DateFormat df = new SimpleDateFormat("yyyyMMdd", CFLocale.getSystem(Locale.US)); Date parsedDate = df.parse("20210525"); System.out.println("Parsed date: " + parsedDate); } }This example parses a date in compact format ("20210525") using the CFLib implementation of the SimpleDateFormat class. It specifies the US locale using CFLocale.getSystem(Locale.US), and throws a ParseException if the input string cannot be parsed as a date.