Date and time Java Exercise - Java Programming Course


Date and time


Create a program to display the current date and time with the following format:

Today is 6 of February of 2015. It´s 03:23:12

 Example Code

public class Main
	public static void main(String[] args)
		String day ="00");
		String month = GetMonth(;
		int year =;
		String time =;

		System.out.printf("Today is %1$s of %2$s of %3$s. It´s %4$s." + "\r\n", day, month, year, time);

	private static String GetMonth(int numberMonth)
		String[] months = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Decenber"};

		return months[numberMonth - 1];

Juan A. Ripoll - Programming Tutorials and Courses © 2024 All rights reserved.  Legal Conditions.