Java Day in Month padMonthOrDay(String mod)

Here you can find the source of padMonthOrDay(String mod)

Description

Pad the month or day with a leading zero

License

Open Source License

Parameter

Parameter Description
mod The month or day to pad

Return

The padded month or day or a blank string if not a valid day or year

Declaration

public static String padMonthOrDay(String mod) 

Method Source Code

//package com.java2s;
/**//w  w  w .  j  ava 2s . c  o  m
 * Archivists' Toolkit(TM) Copyright 2005-2007 Regents of the University of California, New York University, & Five Colleges, Inc.
 * All rights reserved.
 *
 * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL)
 * version 1.0 (http://www.opensource.org/licenses/ecl1.php)
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations.
 *
 *
 * Archivists' Toolkit(TM)
 * http://www.archiviststoolkit.org
 * info@archiviststoolkit.org
 *
 *
 * Simple utility class for checking that an entered date is valid for the given database
 * and for handeling iso dates in the AT
 *
 * Created by IntelliJ IDEA.
 * User: Nathan Stevens
 * Date: Aug 28, 2008
 * Time: 10:46:58 AM
 * To change this template use File | Settings | File Templates.
 */

public class Main {
    /**
     * Pad the month or day with a leading zero
     * @param mod The month or day to pad
     * @return The padded month or day or a blank string if not a valid day or year
     */
    public static String padMonthOrDay(String mod) {
        // fisrt check to see if it is a year that needs to be padded
        if (mod.matches("\\d{2}")) {
            return mod;
        } else if (mod.matches("\\d")) {
            return "0" + mod;
        } else { // month or day format not right return blank
            return "";
        }
    }
}

Related

  1. isDayOfMonth(int num)
  2. isLastDayOfMonth(int day, int month, int year)
  3. maxDayOfMonth(int year, int month)
  4. monthDays(int y, int m)
  5. numDaysInMonth(int month)
  6. toMonthFirstDay(String month)
  7. validateDayOfMonth(int day)
  8. validateMonthDay(int nDate)
  9. weekOfMonth(int dayCount, int commonMonthIndex)