使用SimpleDateFormat在Java中显示今天的日期
要使用Java中的SimpleDateFormat类,请导入以下包。
import java.text.SimpleDateFormat;
要获取日期,请使用format()如下所示的方法。首先,设置日期格式-
Calendar cal = Calendar.getInstance();
SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy");现在,我们将获得日期-
simpleformat.format(cal.getTime())
以下是完整的示例-
示例
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Demo {
public static void main(String[] args) throws Exception {
Calendar cal = Calendar.getInstance();
SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("Today's date = "+simpleformat.format(cal.getTime()));
}
}输出结果
Today's date = 26/11/2018
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短