All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs.joy.datesAndText.SimpleDate Maven / Gradle / Ivy

The newest version!
package edu.pdx.cs.joy.datesAndText;

import java.text.*;
import java.util.*;

/**
 * This program demonstrates how to use the {@link
 * java.text.SimpleDateFormat} class to format and parse dates.
 */
public class SimpleDate {

  public static void main(String[] args) {
    DateFormat df = new SimpleDateFormat(args[0]);
    if (args.length > 1) {
      try {
        df.setLenient(true);
        System.out.println(df.parse(args[1]));

      } catch (ParseException ex) {
        System.err.println("Malformed date: " + args[1]);
      }
      
    } else {
      Date now = new Date();
      System.out.println(df.format(now));
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy