List of utility methods to do Timestamp Create
java.sql.Timestamp | getTimestamp(String strDate) Converts a String date in a "jj/mm/aaaa" format in a java.sql.Timestamp type date ParsePosition pos = new ParsePosition(0); java.util.Date date = _formatter.parse(strDate, pos); if (date != null) { return (new java.sql.Timestamp(date.getTime())); return null; |
Timestamp | getTimestamp(String time, String pattern) get Timestamp DateFormat format = new SimpleDateFormat(pattern); format.setLenient(false); Timestamp ts = null; try { ts = new Timestamp(format.parse(time).getTime()); } catch (ParseException e) { e.printStackTrace(); return ts; |
Timestamp | getTimestamp2() get Timestamp Date dt = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowTime = df.format(dt); java.sql.Timestamp buydate = java.sql.Timestamp.valueOf(nowTime); return buydate; |
String | getTimeStampAsString(Timestamp formatTime) get Time Stamp As String SimpleDateFormat m_format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); return m_format.format(formatTime); |
String | getTimestampAsString(Timestamp tsTimestamp) Convert timestamp to string including it's nanosecond portion so that it can be safely stored in variable of web page. StringBuilder sbTimestamp = new StringBuilder(); sbTimestamp.append(tsTimestamp.getTime()); sbTimestamp.append(NANO_SEPARATOR); sbTimestamp.append(tsTimestamp.getNanos()); return sbTimestamp.toString(); |
Timestamp | getTimestampAtMidnightForDaysAgo(int days) get Timestamp At Midnight For Days Ago Calendar now = new GregorianCalendar(); now.add(Calendar.DAY_OF_YEAR, -days); now.set(Calendar.HOUR_OF_DAY, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); return new Timestamp(now.getTimeInMillis()); |
Timestamp | getTimestampBeforeMs(long someMs) get Timestamp Before Ms return new Timestamp(System.currentTimeMillis() - someMs); |
String | getTimeStampByFormat(String style) get Time Stamp By Format DateFormat format = new SimpleDateFormat(style); return format.format(new Date()); |
String | getTimestampDate(long timestamp) get Timestamp Date return formatDate("dd.MM.yyyy", timestamp); |
String | getTimestampDate(Timestamp ts) get Timestamp Date Calendar c = Calendar.getInstance(); c.setTimeInMillis(ts.getTime()); return formatNumber("00", c.get(Calendar.MONTH) + 1) + "/" + formatNumber("00", c.get(Calendar.DAY_OF_MONTH)) + "/" + formatNumber("00", c.get(Calendar.YEAR) % 100); |