我有一个代码来获取我的一个应用程序的年,月和日.
package com.cera.hyperionUtils;
import java.util.*;
public class HypDate {
public static int curdate(int field)
{
//1. Specify integer 1 for YEAR, 2 for MONTH, 5 DAY_OF_MONTH
Calendar c = new GregorianCalendar();
c.setLenient(true); //Allow overflow
//2. Extract and Return result
if (field == 2) {
field = c.get(Calendar.MONTH) + 1;
}
return c.get(field);
}
public static void main(String[] args)
{
System.out.println(HypDate.curdate(2));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我通过2它正在给0年和日打印正确.....我也试图使月份成为两位数.(像01一样)
有人可以帮帮我吗....?(我是java编码的新手)