简体   繁体   English

%s、%tc、%Tc 的目的是什么?

[英]What is the purpose of %s, %tc, %Tc?

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.这似乎很简单,但我想在这里了解 %s、%tc、%Tc 的用法。

it's for formatting you might check https://www.baeldung.com/java-printstream-printf它用于格式化,您可以检查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这是一个很好的例子: 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此页面的所有学分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM