java - your daily dose of coffee
Dienstag, 16. Juli 2002
conversion: string to SQL timestamp

problem:
you have a date as a string in format dd.mm.yyyy (i.e. 30.12.2001) and you want to convert it to a SQL timestamp string.

Solution:
so what you need is a conversion from the dd.mm.yyyy string to a string with the fromat{ts ‘yyyy-mm-dd’}, which is the string reprensentation of an sql timestamp.

public static String stringToTimestamp(String s) {
	SimpleDateFormat sdfIn = new SimpleDateFormat("dd.MM.yyyy");
	SimpleDateFormat sdfOut = new SimpleDateFormat("yyyy-MM-dd");
	String ret = null;
	try {
		Date d = sdfIn.parse(s);
		ret = sdfOut.format(d);
		ret = "{ts ‘" + ret + "’)";
	} catch (Exception ex) {
		ex.toString();
	}
	return ret;
}

Online for 8168 days
Last modified: 04.01.11, 10:35
Status
Youre not logged in ... Login
Menu
... Home
... Tags

Suche
Calendar
November 2024
So.Mo.Di.Mi.Do.Fr.Sa.
12
3456789
10111213141516
17181920212223
24252627282930
Januar
Recent updates
links Sun JDKs: Sun Java
Portal Web-Techniken: Java Server Pages - Java Webapplikations Technologie Taglibs...
by ...oliver... (29.01.04, 18:03)
[code snippet] windows standard mail-client
aus java heraus starten die garantiert plattformabhängige lösung :-) public...
by herbstkind (13.02.03, 16:45)
bookmark: SAVA - java screen
saver eher zufällig bin ich über diesen link gefallen: .
by herbstkind (17.12.02, 16:47)
bookmark: SAVA - java screen
saver eher zufällig bin ich über diesen link gefallen: .
by herbstkind (17.12.02, 16:47)
SVG Gestern bei Vortrag über
SVG, Gerald Bauer kennengelernt. Sympatischer Workaholic der uns für SVG...
by rolandk (21.11.02, 16:46)
not to let die this
log a hard one for J2EE-heads: .Net beats J2EE by...
by rolandk (04.11.02, 19:16)
info: netbeans 3.4 released the
new version 3.4 of the netbeans ide has been released....
by herbstkind (30.08.02, 12:02)
Look n' Feel Like an
Egyptian I spend the last days by admiring some excellent...
by rolandk (16.08.02, 09:30)
Glorybox The first steps to
my Audio CD Manager program named Glorybox have been made....
by herbstkind (09.08.02, 15:49)
Do We Need Java 3?
OnJava has an artilce by Elliotte Rusty Harold proposing to...
by rolandk (06.08.02, 23:02)
proposals last week during i
was giving a java tutorial. during the tutorial i developped...
by herbstkind (05.08.02, 15:39)
deepClone for Objects a really
tricky idea: public Object deepClone() { try { ByteArrayOutputStream b...
by herbstkind (01.08.02, 18:00)
increase date string by x
days problem you have a date as a string in...
by herbstkind (16.07.02, 18:29)
conversion: string to SQL timestamp
problem: you have a date as a string in format...
by herbstkind (16.07.02, 18:23)
welcome this is my second
weblog in antville. i deceided to create another one since...
by herbstkind (16.07.02, 18:06)

RSS feed

Made with Antville
Helma Object Publisher