Answers for "how to get current year in java"

4

java get current year

import java.util.Calendar;

int year = Calendar.getInstance().get(Calendar.YEAR);
Posted by: Guest on November-06-2020
0

java get year from date

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = format.parse(datetime);
SimpleDateFormat df = new SimpleDateFormat("yyyy");
year = df.format(date);
Posted by: Guest on October-08-2020
1

java get year

import java.time.ZoneId;
import java.util.Date;

new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().getYear();
Posted by: Guest on September-03-2020
-1

get current day java

Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK); 

switch (day) {
    case Calendar.SUNDAY:
        // Current day is Sunday
        break;
    case Calendar.MONDAY:
        // Current day is Monday
        break;
    case Calendar.TUESDAY:
        // etc.
        break;
}
Posted by: Guest on March-29-2020

Code answers related to "how to get current year in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language