How to get the current year in yy format with Java

2 Answers

0 votes
import java.util.Calendar;

public class MyClass {
    public static void main(String args[]) {
        Calendar cal = Calendar.getInstance();
        
        int year = cal.get(Calendar.YEAR) % 100;
   
        System.out.print(year);
    }
}
 

 
 
/*
run:
 
23
 
*/

 



answered May 14, 2023 by avibootz
0 votes
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
 
public class MyClass {
    public static void main(String args[]) {
        Calendar cal = Calendar.getInstance();

        SimpleDateFormat simpleformat = new SimpleDateFormat("yy");
             
        String year = simpleformat.format(new Date());
         
        System.out.println(year);
    }
}
  
 
  
  
  
/*
run:
  
23
  
*/

 



answered May 14, 2023 by avibootz
edited May 15, 2023 by avibootz

Related questions

1 answer 121 views
1 answer 104 views
1 answer 110 views
1 answer 137 views
1 answer 104 views
104 views asked Dec 21, 2022 by avibootz
...