Created
July 14, 2017 17:09
-
-
Save P0huber/f1a5f133fbc35c2a2604c5ea7acfcb61 to your computer and use it in GitHub Desktop.
The printing the current date. Вывод текущей даты [Java]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task05.task0528; | |
/* | |
Вывести на экран сегодняшнюю дату | |
*/ | |
import java.text.SimpleDateFormat; | |
import java.time.LocalDateTime; | |
import java.time.ZonedDateTime; | |
import java.time.format.DateTimeFormatter; | |
import java.util.Calendar; | |
import java.util.Date; | |
public class CurrentDate { | |
public static void main(String[] args) { | |
System.out.println(LocalDateTime.now());//in Java 8 we can use "java.time.LocalDateTime;" | |
System.out.println(); | |
System.out.println(ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME));//java.text.SimpleDateFormat; and java.time.format.DateTimeFormatter; | |
System.out.println(); | |
Date d = new Date(); | |
System.out.println(System.currentTimeMillis());//single numeric value in milliseconds, delta from a UTC time-point | |
System.out.println(d); | |
System.out.println(); | |
System.out.println(Calendar.getInstance());//APIs are cumbersome | |
System.out.println(); | |
String timeStamp = new SimpleDateFormat("dd MM yyyy").format(Calendar.getInstance().getTime());//java.util.Calendar; and java.text.SimpleDateFormat; | |
System.out.println(timeStamp); | |
System.out.println(); | |
System.out.println( new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));//java.util.Date | |
//System.out.println(org.joda.time.DateTime());//Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java.time (JSR-310). | |
} | |
} | |
/*Вывести на экран сегодняшнюю дату | |
Вывести на экран текущую дату в аналогичном виде «21 02 2014«. | |
Требования: | |
1. Дата должна содержать день, месяц и год, разделенные пробелом. | |
2. День должен соответствовать текущему. | |
3. Месяц должен соответствовать текущему. | |
4. Год должен соответствовать текущему. | |
5. Вся дата должна быть выведена в одной строке.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment