How to get current year in android?

Shubh :

I tried

int year = Calendar.get(Calendar.YEAR);

but it is giving me compile time error that

Non-static method 'get(int)' cannot be referenced from a static context.

I am calling this method from call method of observable.

Observable.combineLatest(ob1 ob2,
                ob3, new Func3<String, String, String, Boolean>() {
                    @Override
                    public Boolean call(String a, String b, String c) {...

I had also seen (new Date()).getYear(); but it is deprecated.

dsncode :

Because you need to create an instance first.

try this

Calendar.getInstance().get(Calendar.YEAR);

and you are good to go.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=446060&siteId=1