Good day! Made such a task. Create an application that displays the name of the developer, the date and time of receipt of the task, as well as the date and time of delivery of the task. To get the latest date and time, use the Calendar class from the java.util package.

Posted by:

import java.util.Calendar; import java.util.Date; public class Test{ public static void main (String args []){ String s = "Василевса"; Date d = new Date(); System.out.println("Получения задания для " + s + " " + d); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR,2011); c.set(Calendar.MONTH,Calendar.JUNE); c.set(Calendar.DAY_OF_MONTH,30); System.out.println("Сдача задания для " + s + " " + c.getTime()); } } 

Displays the result:

Getting the job for Vasileus Mon May 23 19:26:42 BDT 2011

Delivery of the assignment for Vasilev Thu Jun 30 19:26:42 BDT 2011

  1. How can you alter or add, to deduce another time, where it is written Delivery of the task displays the time 19:26:42, but you need to change it for another time.
  2. I also wanted the result to output in Russian without the time of minutes and seconds.

Like this:

Getting a job for Vasilevs Monday May 23 2011 or Monday May 23, 2011 or Monday 23.05.2011

Delivery of the assignment for Vasilevs Wednesday June 30 2011 or Wednesday 30 June 2011 or Wednesday 30.06.2011

    1 answer 1

    Use SimpleDateFormat with a constructor specifying a locale: SimpleDateFormat (pattern, locale)

      Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("EEEE", Locale.GERMANY); System.out.println(sdf.format(c.getTime())); SimpleDateFormat sdf2 = new SimpleDateFormat("EEEE", Locale.getDefault()); System.out.println(sdf2.format(c.getTime())); 

    At the exit:

     Donnerstag четверг 


    And yes, there is another alternative way: you can specify this locale on the calendar itself:

     calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.GERMANY) 

    But it is less convenient in practice, but sometimes useful.

    • Many thanks for the answer I will try to do !!! - turtles