How to resolve the algorithm Date manipulation step by step in the Scala programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Date manipulation step by step in the Scala programming language

Table of Contents

Problem Statement

Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Date manipulation step by step in the Scala programming language

Source code in the scala programming language

import java.text.SimpleDateFormat
import java.util.{Calendar, Locale, TimeZone}

object DateManipulation {
  def main(args: Array[String]): Unit = {
    val input="March 7 2009 7:30pm EST"
    val df=new SimpleDateFormat("MMMM d yyyy h:mma z", Locale.ENGLISH)
    val c=Calendar.getInstance()
    c.setTime(df.parse(input))
	 
    c.add(Calendar.HOUR_OF_DAY, 12)
    println(df.format(c.getTime))
	 
    df.setTimeZone(TimeZone.getTimeZone("GMT"))
    println(df.format(c.getTime))
  }
}


  

You may also check:How to resolve the algorithm Conway's Game of Life step by step in the PL/I programming language
You may also check:How to resolve the algorithm Benford's law step by step in the Python programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm CRC-32 step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Standard ML programming language