Java Year Get getYear(String date)

Here you can find the source of getYear(String date)

Description

get Year

License

Open Source License

Declaration

public static int getYear(String date) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static int getYear(String date) {
        date = deleteSlash(date);/*from ww  w .j  ava  2 s .co  m*/
        date = deleteDash(date);
        return Integer.parseInt(date.substring(0, 4));
    }

    public static String deleteSlash(String value) {
        return deleteChar(value, "/");
    }

    public static String deleteDash(String value) {

        return deleteChar(value, "-");
    }

    public static String deleteChar(String source, String deleteStr) {
        if (source == null || "".equals(source.trim())) {
            return "";
        }
        StringBuffer temp = new StringBuffer("");
        StringTokenizer st = new StringTokenizer(source, deleteStr);

        while (st.hasMoreTokens()) {
            temp.append(st.nextToken());
        }

        return temp.toString();
    }
}

Related

  1. getYear(long date)
  2. getYear(String aDate)
  3. GetYear(String agmipDate)
  4. getYear(String argDate)
  5. getYear(String date)
  6. getYear(String date)
  7. getYear(String date)
  8. getYear(String dateKey)
  9. getYear(String datetime)