Get Year from Date in Java - Example Code
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; // // The following example code demonstrates how to // print out the Year from a Date object. // public class GetYearFromDate { public static void main(String[] args) { Date now = new Date(); SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy"); System.out.println(simpleDateformat.format(now)); } }
Here is the output of the example code:
2011
No comments:
Post a Comment