I was studying a program about getting dates, time and then after browsing online I see this one:
System.out.printf("The date is %s\n", new Date() );
System.out.printf("The date is %tc\n", new Date() );
System.out.printf("The DATE is %Tc\n", new Date() );
which seems to be straightforward but I want to understand the use of %s, %tc, %Tc here.
it's for formatting you might check https://www.baeldung.com/java-printstream-printf
These are special characters that are being used to format a date. Here is a good example for this: http://www.java2s.com/Tutorial/Java/0120__Development/UnixdateformattcTc.htm
import java.util.Date;
public class MainClass {
public static void main(String[] args) {
Date now = new Date();
System.out.printf("Unix date format: %tc/%Tc\n", now, now);
}
}
And the result:
Unix date format: Thu May 24 15:58:29 PDT 2007/THU MAY 24 15:58:29 PDT 2007
All credits to this page
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.