Java Programing laungage

java.util Projects

java.util Project 1

Getting Previous, Current and Next Day Date

In this page of the tutorials, we shall be learn how to get previous, current and next date in java. The java util package provides the facility for it.

Previous Home Next
adplus-dvertising

Program Description

This example is help us to get the previous, current and next date to Date() constructor of java.util.*; package. at First we are need to put a current date in the GMT format. SimpleDateFormat()changes the GMT format according to user's requirements. For getting the previous date subtract a day in MILLIS_IN_DAY and add a day for getting the next date.

Example


package r4r;
import java.text.SimpleDateFormat;
import java.util.*;
public class currentdatetest {
public static void main(String[] args) {
int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
Date day = new Date();
SimpleDateFormat Format = new SimpleDateFormat("dd/MM/yy"); String preDate = Format.format(day.getTime() - MILLIS_IN_DAY); String curDate = Format.format(day.getTime()); String NextDate = Format.format(day.getTime() + MILLIS_IN_DAY); System.out.println("Previous date is: " + preDate); System.out.println("Currnent date is: " + curDate); System.out.println("Next date is: " + NextDate); } }
Previous Home Next