Scala Program to Print Yesterday’s Date

Scala Program to Print Yesterday's Date

Scala program to print yesterday’s date

// Scala program to print yesterday's date

import java.util.Date;

object Sample {
  def main(args: Array[String]) {
    var MILLIS_IN_A_DAY = 1000 * 60 * 60 * 24;
    var date = new Date();
    var previousDate = new Date(date.getTime() - MILLIS_IN_A_DAY);

    println("Today's date: \n" + date);
    println("Yesterday's date: \n" + previousDate);
  }
}

Output

Today's date: 
Mon May 31 02:08:37 GMT 2021
Yesterday's date: 
Sun May 30 02:08:37 GMT 2021
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment