Java Year Get getYear(Date dt)

Here you can find the source of getYear(Date dt)

Description

Get year string for the specified date.

License

Open Source License

Parameter

Parameter Description
dt Specified date.

Return

The year string of specified date.

Declaration

public static String getYear(Date dt) 

Method Source Code

//package com.java2s;
/*//from  ww w.jav a  2s.  c  o  m
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
 *
 * The contents of this file are subject to the terms of the Common 
 * Development and Distribution License ("CDDL")(the "License"). You 
 * may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the License at
 * https://open-dm-mi.dev.java.net/cddl.html
 * or open-dm-mi/bootstrap/legal/license.txt. See the License for the 
 * specific language governing permissions and limitations under the  
 * License.  
 *
 * When distributing the Covered Code, include this CDDL Header Notice 
 * in each file and include the License file at
 * open-dm-mi/bootstrap/legal/license.txt.
 * If applicable, add the following below this CDDL Header, with the 
 * fields enclosed by brackets [] replaced by your own identifying 
 * information: "Portions Copyrighted [year] [name of copyright owner]"
 */

import java.util.Date;

import java.text.FieldPosition;
import java.text.SimpleDateFormat;

public class Main {
    /**
     * Get year string for the specified date.
     *
     * @param dt Specified date.
     * @return The year string of specified date.
     */
    public static String getYear(Date dt) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        StringBuffer sb = new StringBuffer();
        sdf.format(dt, sb, new FieldPosition(0));

        return sb.toString();
    }
}

Related

  1. getYear(Date date)
  2. getYear(Date date)
  3. getYear(Date date)
  4. getYear(Date date)
  5. getYear(Date date, TimeZone timeZone)
  6. getYear(final Date date)
  7. getYear(final String date)
  8. getYear(final String date)
  9. getYear(int year)