public class DateExample1 { public static void main(String[] args) { // Get the system date/time Date date = new Date(); System.out.println(date.getTime()); } }
public static void main(String[] args) { SimpleDateFormat bartDateFormat = new SimpleDateFormat ("EEEE-MMMM-dd-yyyy"); Date date = new Date(); System.out.println(bartDateFormat.format(date)); } }
public class DateExample3 { public static void main(String[] args) { // Create a date formatter that can parse dates of the form MM-dd-yyyy. SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy");
// Create a string containing a text date to be parsed. String dateStringToParse = "8-8-2005"; try { // Parse the text version of the date. //We have to perform the parse method in a //try-catch construct in case dateStringToParse //does not contain a date in the format we are expecting. Date date = bartDateFormat.parse(dateStringToParse); // Now send the parsed date as a long value // to the system output. System.out.println(date.getTime()); } catch (Exception ex){ System.out.println(ex.getMessage()); } } }