Java Year From yearOfDate(Date s)

Here you can find the source of yearOfDate(Date s)

Description

year Of Date

License

Open Source License

Declaration

static public int yearOfDate(Date s) throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from   w  ww. ja va 2  s .  co  m*/
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    static public int yearOfDate(Date s) throws ParseException {
        String d = FORMAT_YYYY_MM_DD.format(s);
        return Integer.parseInt(d.substring(0, 4));
    }

    static public String format(Date date, String formatText) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(formatText);
        return format.format(date);
    }
}

Related

  1. year(long time)
  2. yearformMatDate(Date date)
  3. yearFromDate(String date)
  4. yearFromDateValue(long x)
  5. yearFromFileName(String str)
  6. yearsBetween(String from, String to)