Java SQL Date Convert dateToString(java.sql.Date d)

Here you can find the source of dateToString(java.sql.Date d)

Description

dateToString takes a JDBC date and makes it a mm/dd string

License

Open Source License

Parameter

Parameter Description
d ate to translate to string

Return

The ascii string in yyyy/mm/dd

Declaration

public static String dateToString(java.sql.Date d) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .  j a v  a2  s .  co  m*/
 * Copyright 2010, United States Geological Survey or
 * third-party contributors as indicated by the @author tags.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program 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
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.util.StringTokenizer;

public class Main {
    /** dateToString takes a JDBC date and makes it a mm/dd string 
     *@param d ate to translate to string
     *@return The ascii string in yyyy/mm/dd*/
    public static String dateToString(java.sql.Date d) {
        if (d == null)
            return "";
        String s = d.toString(); // returns yyyy-mm-dd
        if (s == null)
            if (s.equals("null"))
                return "";
        //    Util.prt("datetostring="+s);
        StringTokenizer tk = new StringTokenizer(s, "-");

        int yr = Integer.parseInt(tk.nextToken());
        int mon = Integer.parseInt(tk.nextToken());
        int day = Integer.parseInt(tk.nextToken());
        return "" + mon + "/" + day + "/" + yr;

    }
}

Related

  1. dateToStamp(String date)
  2. dateToSTR(Date data, String formato)
  3. dateToStr(java.util.Date date)
  4. dateToString(Date date)
  5. dateToString(Date date, String format)
  6. dateToString(java.sql.Date data)
  7. dateToString(java.sql.Date datee)
  8. dateToString(java.util.Date date, String dateFmt)
  9. to2GMTString(final Date tsStart, final Date tsEnd)