Here you can find the source of getYear(Date dt)
Parameter | Description |
---|---|
dt | Specified date. |
public static String getYear(Date dt)
//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(); } }