Here you can find the source of dateToString(java.sql.Date d)
Parameter | Description |
---|---|
d | ate to translate to string |
public static String dateToString(java.sql.Date d)
//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; } }