date format app

2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import java.util.Date; import java. text.SimpleDateFormat ; class DateFormatApp { public static void main(String[] args) { try { Date myDate = new Date(); System.out.println(myDate); SimpleDateFormat mdyFormat = new SimpleDateFormat ("d SimpleDateFormat dmyFormat = new SimpleDateFormat ("y  // Format th e date to Strings String mdy = mdyFormat.format(myDate); String dmy = dmyFormat.format(myDate);  // Results.. . System.out.println(mdy); System.out.println(dmy);  // Parse the Strin gs back to dates  // Note, the formats don't "st ick" with the Date v alue System.out.println(mdyFormat.parse(mdy)); System.out.println(dmyFormat. parse(dmy)); } catch (Exception exp) { exp.printStackTrace(); } } } DateFormatApp.java 18-Jun-16 6:52 AM Page 1 of 1

Upload: subashnayak999

Post on 01-Mar-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Date Format App

7/26/2019 Date Format App

http://slidepdf.com/reader/full/date-format-app 1/1

1234

56789

10111213

141516171819202122

232425262728293031

import java.util.Date;import java.text.SimpleDateFormat;

class DateFormatApp

{public static void main(String[] args){

try {Date myDate = new Date();System.out.println(myDate);

SimpleDateFormat mdyFormat = new SimpleDateFormat("dSimpleDateFormat dmyFormat = new SimpleDateFormat("y

 // Format the date to StringsString mdy = mdyFormat.format(myDate);String dmy = dmyFormat.format(myDate);

 // Results...System.out.println(mdy);System.out.println(dmy); // Parse the Strings back to dates

 // Note, the formats don't "stick" with the Date valueSystem.out.println(mdyFormat.parse(mdy));System.out.println(dmyFormat.parse(dmy));} catch (Exception exp) {

exp.printStackTrace();}

}}

DateFormatApp.java 18-Jun-16 6:52 AM

Page 1 of 1