Using Java Class "Date" you can get date using Date d = new Date();
Java Provies class named SimpleDateFormat which allows to format date to specific DateFormat.
Using Following program You can :
Output :
Java Provies class named SimpleDateFormat which allows to format date to specific DateFormat.
Using Following program You can :
- Retrieve Current Date in Java
- Retrieve Previous Date in Java
- Retrieve Next Date in Java
package com.anuj.basic; import java.text.SimpleDateFormat; import java.util.Date; /** * * @author Anuj Patel */ public class DateOperations { public static void main(String[] args) { int MILLIS_IN_DAY = 1000 * 60 * 60 * 24; Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy"); String prevDate = dateFormat.format(date.getTime() - MILLIS_IN_DAY); String currDate = dateFormat.format(date.getTime()); String nextDate = dateFormat.format(date.getTime() + MILLIS_IN_DAY); System.out.println("Previous date: " + prevDate); System.out.println("Currnent date: " + currDate); System.out.println("Next date: " + nextDate); } }
Previous date: 03/11/12 Currnent date: 04/11/12 Next date: 05/11/12
No comments:
Post a Comment