本文整理汇总了Java中java.sql.Timestamp.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Timestamp.toString方法的具体用法?Java Timestamp.toString怎么用?Java Timestamp.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Timestamp
的用法示例。
在下文中一共展示了Timestamp.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSqlTimestampString
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* 根据指定的格式转换java.sql.Timestamp到String
*
* @param dt
* java.sql.Timestamp instance
* @param sFmt
* Date 格式,DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME/
* DATE_FORMAT_SESSION
* @return
* @since 1.0
* @history
*/
public static String toSqlTimestampString(Timestamp dt, String sFmt) {
String temp = null;
String out = null;
if (dt == null || sFmt == null) {
return null;
}
temp = dt.toString();
if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME) || // "YYYY/MM/DD
// HH24:MI:SS"
sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) { // YYYY/MM/DD
temp = temp.substring(0, sFmt.length());
out = temp.replace('/', '-');
// }else if( sFmt.equals (DateUtils.DATE_FORMAT_SESSION ) ){
// //Session
// out =
// temp.substring(0,4)+temp.substring(5,7)+temp.substring(8,10);
// out += temp.substring(12,14) + temp.substring(15,17);
}
return out;
}
示例2: updateMovieImage
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* Upload image file to Azure blob and save its relative path to database.
*
* @param file image file
* @param id movie id
* @return updated movie detail page
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String updateMovieImage(@RequestParam("file") MultipartFile file, @RequestParam("id") Long id) {
logger.debug(file.getOriginalFilename());
String newName = id + "." + FilenameUtils.getExtension(file.getOriginalFilename());
String imageUri = this.azureStorageUploader.uploadToAzureStorage(applicationContext, file, newName.toLowerCase());
if (imageUri != null) {
Timestamp timestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
String timestampQuery = "?timestamp=" + timestamp.toString();
Movie movie = new Movie();
movie.setImageUri(imageUri.toLowerCase() + timestampQuery);
movieRepository.patchMovie(Long.toString(id), movie);
}
return "redirect:/movies/" + id;
}
示例3: toSqlTimestampString
import java.sql.Timestamp; //导入方法依赖的package包/类
/**
* 根据指定的格式转换java.sql.Timestamp到String
*
* @param dt
* java.sql.Timestamp instance
* @param sFmt
* Date 格式,DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME/
* DATE_FORMAT_SESSION
* @return
* @since 1.0
* @history
*/
public static String toSqlTimestampString(Timestamp dt, String sFmt) {
String temp = null;
String out = null;
if (dt == null || sFmt == null) {
return null;
}
temp = dt.toString();
if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME) || // "YYYY/MM/DD
// HH24:MI:SS"
sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) { // YYYY/MM/DD
temp = temp.substring(0, sFmt.length());
out = temp.replace('/', '-');
// }else if( sFmt.equals (DateUtils.DATE_FORMAT_SESSION ) ){
// //Session
// out =
// temp.substring(0,4)+temp.substring(5,7)+temp.substring(8,10);
// out += temp.substring(12,14) + temp.substring(15,17);
}
return out;
}
示例4: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
int year = RandomParameters.randBetween(1993, 1997);
int month = RandomParameters.randBetween(1, 12);
long date1 = RandomParameters.convertDatetoLong(year, month, 1);
long date2 = RandomParameters.convertDatetoLong(year+1, month, 1);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query = "SELECT (100.00 * sum(CASE WHEN i_data LIKE 'PR%' THEN ol_amount ELSE 0 END) / (1 + sum(ol_amount))) AS promo_revenue "
+ "FROM "
+ HTAPBConstants.TABLENAME_ORDERLINE + ", "
+ HTAPBConstants.TABLENAME_ITEM
+ " WHERE ol_i_id = i_id "
+ "AND ol_delivery_d >= '"+ts1.toString()+"' "
+ "AND ol_delivery_d < '"+ts2.toString()+"'";
return new SQLStmt(query);
}
示例5: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
//compute random number of days [60,120]
int days = RandomParameters.randBetween(60, 120);
//transform tpch into the correct TS in our populate.
long tpch = clock.getCurrentTs();
//compute the correct TS considering the delay
long ts_plusXdays = clock.computeTsMinusXDays(tpch, days);
Timestamp ts = new Timestamp(clock.transformTsFromSpecToLong(ts_plusXdays));
String query = "SELECT ol_number, "
+ "sum(ol_quantity) AS sum_qty, "
+ "sum(ol_amount) AS sum_amount, "
+ "avg(ol_quantity) AS avg_qty, "
+ "avg(ol_amount) AS avg_amount, "
+ "count(*) AS count_order "
+ "FROM "+ HTAPBConstants.TABLENAME_ORDERLINE
+ " WHERE ol_delivery_d > '"
+ ts.toString()
+ "' GROUP BY ol_number "
+ "ORDER BY ol_number";
return new SQLStmt(query);
}
示例6: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
int year = RandomParameters.randBetween(1993, 1997);
long date1 = RandomParameters.convertDatetoLong(year, 1, 1);
long date2 = RandomParameters.convertDatetoLong(year+1, 1, 1);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query = "SELECT o_ol_cnt, "
+ "sum(CASE WHEN o_carrier_id = 1 "
+ "OR o_carrier_id = 2 THEN 1 ELSE 0 END) AS high_line_count, "
+ "sum(CASE WHEN o_carrier_id <> 1 "
+ "AND o_carrier_id <> 2 THEN 1 ELSE 0 END) AS low_line_count "
+ "FROM "
+ HTAPBConstants.TABLENAME_ORDER + ", "
+ HTAPBConstants.TABLENAME_ORDERLINE
+ " WHERE ol_w_id = o_w_id "
+ "AND ol_d_id = o_d_id "
+ "AND ol_o_id = o_id "
+ "AND o_entry_d <= ol_delivery_d "
+ "AND ol_delivery_d >= '"+ts1.toString()+"' "
+ "AND ol_delivery_d < '"+ts2.toString()+"' "
+ "GROUP BY o_ol_cnt "
+ "ORDER BY o_ol_cnt";
return new SQLStmt(query);
}
示例7: formatValue
import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public <T> String formatValue(final T value, final String sqlDataType, final String fullTableName, final String tableName, final String columnName) {
if (value == null) {
return "NULL";
}
switch (sqlDataType) {
case "VARCHAR":
case "VARCHAR2":
// varchar has to be wrapped in single quotation marks
return "'" + value.toString().replace("'", "''") + "'";
case "DECIMAL":
case "NUMBER":
//check is it is a boolean that is being saved as a number
if (value instanceof Boolean) {
return (Boolean) value ? "1" : "0";
}
// All java decimals implement a proper toString() method
return value.toString();
default:
break;
}
if (value instanceof java.util.Date) {
Date d = (Date) value;
Timestamp t = new Timestamp(d.getTime());
return "TO_TIMESTAMP('" + t.toString() + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
}
if (value instanceof TemporalAccessor) {
TemporalAccessor temporalAccessor = (TemporalAccessor) value;
String s = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").format(temporalAccessor);
return "TO_TIMESTAMP('" + s + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
}
LOG.warn("No mapping for {}. Returning result of toString()", sqlDataType);
return value.toString();
}
示例8: getAllEventsInfo
import java.sql.Timestamp; //导入方法依赖的package包/类
public List<Map<String, Object>> getAllEventsInfo() throws SQLException {
List<Map<String, Object>> lst_events = new ArrayList<>();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from event_info";
con = DBConnection.getConnection();
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> eventInfo = new HashMap<String, Object>();
eventInfo.put("eventd", rs.getInt(1));
eventInfo.put("latitude", rs.getDouble(2));
eventInfo.put("Longitude", rs.getDouble(3));
Timestamp eventEntireDate = rs.getTimestamp(4);
if (eventEntireDate != null) {
String eventDateTimeStr = eventEntireDate.toString();
eventInfo.put("date", eventDateTimeStr.substring(0, 10));
eventInfo.put("time", eventDateTimeStr.substring(11, eventDateTimeStr.length()));
}
eventInfo.put("eventName", rs.getString(5));
lst_events.add(eventInfo);
}
con.close();
return lst_events;
}
示例9: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
RandomParameters random = new RandomParameters("uniform");
String nation = random.getRandomNation();
String char1 = random.generateRandomCharacter()+"%";
int year = RandomParameters.randBetween(1993, 1997);
int month = RandomParameters.randBetween(1, 12);
long date1 = RandomParameters.convertDatetoLong(year, month, 1);
long date2 = RandomParameters.convertDatetoLong(year+1, month, 1);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query = "SELECT su_name, "
+ "su_address "
+ "FROM "
+ HTAPBConstants.TABLENAME_SUPPLIER + ", "
+ HTAPBConstants.TABLENAME_NATION
+ " WHERE su_suppkey IN "
+ "(SELECT mod(s_i_id * s_w_id, 10000) "
+ "FROM " + HTAPBConstants.TABLENAME_STOCK
+ " INNER JOIN "+ HTAPBConstants.TABLENAME_ITEM+" ON i_id = s_i_id "
+ "INNER JOIN "+HTAPBConstants.TABLENAME_ORDERLINE+" ON ol_i_id = s_i_id "
+ "WHERE ol_delivery_d >= '"+ts1.toString()+"' "
+ "AND ol_delivery_d < '"+ts2.toString()+"' "
+ "AND i_data LIKE '"+char1+"' "
+ "GROUP BY s_i_id, "
+ "s_w_id, "
+ "s_quantity HAVING 2*s_quantity > sum(ol_quantity)) "
+ "AND su_nationkey = n_nationkey "
+ "AND n_name = '"+nation+"' "
+ "ORDER BY su_name";
return new SQLStmt(query);
}
示例10: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
RandomParameters random = new RandomParameters("uniform");
String region = random.getRandomRegion();
int year = RandomParameters.randBetween(1993, 1997);
long date1 = RandomParameters.convertDatetoLong(year, 1, 1);
long date2 = RandomParameters.convertDatetoLong(year+1, 1, 1);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query = "SELECT n_name, "
+ "sum(ol_amount) AS revenue "
+ "FROM "
+ HTAPBConstants.TABLENAME_CUSTOMER + ", "
+ HTAPBConstants.TABLENAME_ORDER + ", "
+ HTAPBConstants.TABLENAME_ORDERLINE+ ", "
+ HTAPBConstants.TABLENAME_STOCK + ", "
+ HTAPBConstants.TABLENAME_SUPPLIER + ", "
+ HTAPBConstants.TABLENAME_NATION + ", "
+ HTAPBConstants.TABLENAME_REGION
+ " WHERE c_id = o_c_id "
+ "AND c_w_id = o_w_id "
+ "AND c_d_id = o_d_id "
+ "AND ol_o_id = o_id "
+ "AND ol_w_id = o_w_id "
+ "AND ol_d_id=o_d_id "
+ "AND ol_w_id = s_w_id "
+ "AND ol_i_id = s_i_id "
+ "AND su_nationkey = n_nationkey "
+ "AND n_regionkey = r_regionkey "
+ "AND r_name = '"+region+"' "
+ "AND o_entry_d >= '"+ts1.toString()+"' "
+ "AND o_entry_d < '"+ts2.toString()+"' "
+ "GROUP BY n_name "
+ "ORDER BY revenue DESC";
return new SQLStmt(query);
}
示例11: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
RandomParameters random = new RandomParameters("uniform");
String nation1 = random.getRandomNation();
String nation2 = random.getRandomNation();
long date1 = RandomParameters.convertDatetoLong(1995, 1, 1);
long date2 = RandomParameters.convertDatetoLong(1996, 12, 31);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query = "SELECT su_nationkey AS supp_nation, "
+ "sum(ol_amount) AS revenue "
+ "FROM "
+ HTAPBConstants.TABLENAME_SUPPLIER+ ", "
+ HTAPBConstants.TABLENAME_STOCK + ", "
+ HTAPBConstants.TABLENAME_ORDERLINE+ ", "
+ HTAPBConstants.TABLENAME_ORDER + ", "
+ HTAPBConstants.TABLENAME_CUSTOMER + ", "
+ HTAPBConstants.TABLENAME_NATION + " n1, "
+ HTAPBConstants.TABLENAME_NATION + " n2 "
+ "WHERE ol_supply_w_id = s_w_id "
+ "AND ol_i_id = s_i_id "
+ "AND ol_w_id = o_w_id "
+ "AND ol_d_id = o_d_id "
+ "AND ol_o_id = o_id "
+ "AND c_id = o_c_id "
+ "AND c_w_id = o_w_id "
+ "AND c_d_id = o_d_id "
+ "AND su_nationkey = n1.n_nationkey "
+ "AND substr(c_state,1,1) = substr(n2.n_name,1,1) "
+ "AND ((n1.n_name = '"+nation1+"' "
+ "AND n2.n_name = '"+nation2+"') "
+ "OR (n1.n_name = '"+nation2+"' "
+ "AND n2.n_name = '"+nation1+"')) "
+ "AND ol_delivery_d between '"+ts1.toString()+"' and '"+ts2.toString()
+ "' GROUP BY su_nationkey "
+ "ORDER BY su_nationkey, "
;
return new SQLStmt(query);
}
示例12: buildViewStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildViewStmt(Clock clock){
int year = RandomParameters.randBetween(1993, 1997);
int month=0;
if(year == 1997)
month = RandomParameters.randBetween(1, 10);
else
month = RandomParameters.randBetween(1, 12);
long date1 = RandomParameters.convertDatetoLong(year, month, 1);
long date2 = RandomParameters.addMonthsToDate(date1, 3);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String view = "CREATE view revenue0 (supplier_no, total_revenue) AS "
+ "SELECT "
+ "mod((s_w_id * s_i_id),10000) as supplier_no, "
+ "sum(ol_amount) as total_revenue "
+ "FROM "
+ HTAPBConstants.TABLENAME_ORDERLINE + ", "
+ HTAPBConstants.TABLENAME_STOCK
+ " WHERE "
+ "ol_i_id = s_i_id "
+ "AND ol_supply_w_id = s_w_id "
+ "AND ol_delivery_d between '"+ts1.toString()+"' AND '"+ts2.toString()
+ "' GROUP BY "
+ "supplier_no";
return new SQLStmt(view);
}
示例13: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
int year = RandomParameters.randBetween(1993, 1997);
int month=0;
if(year == 1997)
month = RandomParameters.randBetween(1, 10);
else
month = RandomParameters.randBetween(1, 12);
long date1 = RandomParameters.convertDatetoLong(year, month, 1);
long date2 = RandomParameters.addMonthsToDate(date1, 3);
Timestamp ts1 = new Timestamp(clock.transformTsFromSpecToLong(date1));
Timestamp ts2 = new Timestamp(clock.transformTsFromSpecToLong(date2));
String query ="SELECT o_ol_cnt, "
+ "count(*) AS order_count "
+ "FROM "
+ HTAPBConstants.TABLENAME_ORDER+" WHERE "
+ "o_entry_d >= '"
+ ts1.toString()
+ "' and o_entry_d < '"
+ ts2.toString()
+ "' and exists "
+ "(SELECT * "
+ "FROM "
+ HTAPBConstants.TABLENAME_ORDERLINE + " WHERE o_id = ol_o_id "
+ "AND o_w_id = ol_w_id "
+ "AND o_d_id = ol_d_id "
+ "AND ol_delivery_d >= o_entry_d) "
+ "GROUP BY o_ol_cnt "
+ "ORDER BY o_ol_cnt";
return new SQLStmt(query);
}
示例14: buildQueryStmt
import java.sql.Timestamp; //导入方法依赖的package包/类
private SQLStmt buildQueryStmt(Clock clock){
RandomParameters random = new RandomParameters("uniform");
int day = RandomParameters.randBetween(1, 31);
long date = RandomParameters.convertDatetoLong(1995, 3, day);
Timestamp ts = new Timestamp(clock.transformTsFromSpecToLong(date));
String state = random.generateRandomCharacter();
state=state.toUpperCase();
state = state+"%";
String query ="SELECT ol_o_id, "
+ "ol_w_id, "
+ "ol_d_id, "
+ "sum(ol_amount) AS revenue, "
+ "o_entry_d "
+ "FROM "
+ HTAPBConstants.TABLENAME_CUSTOMER + ", "
+ HTAPBConstants.TABLENAME_NEWORDER + ", "
+ HTAPBConstants.TABLENAME_ORDER + ", "
+ HTAPBConstants.TABLENAME_ORDERLINE
+ " WHERE c_state LIKE '"+state+"' "
+ "AND c_id = o_c_id "
+ "AND c_w_id = o_w_id "
+ "AND c_d_id = o_d_id "
+ "AND no_w_id = o_w_id "
+ "AND no_d_id = o_d_id "
+ "AND no_o_id = o_id "
+ "AND ol_w_id = o_w_id "
+ "AND ol_d_id = o_d_id "
+ "AND ol_o_id = o_id "
+ "AND o_entry_d > '"+ts.toString()+"' "
+ "GROUP BY ol_o_id, "
+ "ol_w_id, "
+ "ol_d_id, "
+ "o_entry_d "
+ "ORDER BY revenue DESC , o_entry_d";
return new SQLStmt(query);
}
示例15: Gaze
import java.sql.Timestamp; //导入方法依赖的package包/类
public Gaze(double left_x, double right_x, double left_y, double right_y,
double left_validity, double right_validity,
double left_pupil_diameter, double right_pupil_diameter,
long trackerTime) {
this.left_x = left_x;
this.right_x = right_x;
this.left_y = left_y;
this.right_y = right_y;
this.x = (left_x + right_x) / 2;
this.y = (left_y + right_y) / 2;
this.trackerTime = trackerTime;
this.left_validity = left_validity;
this.right_validity = right_validity;
calendar.setTimeInMillis(systemTime);
nanoseconds = (int) (nanoTime%1000000000);
timestamp = new Timestamp(systemTime);
//timestamp.setNanos(nanoseconds);
timestampString = timestamp.toString();
timestampString = timestampString.substring(0, 10) + "T" + timestampString.substring(11);
if(calendar.get(Calendar.ZONE_OFFSET) < 0) timestampString += "-";
else timestampString += "+";
if(Math.abs((calendar.get(Calendar.ZONE_OFFSET)/3600000)) < 10) timestampString += 0;
timestampString += Math.abs((calendar.get(Calendar.ZONE_OFFSET)/3600000)) + ":00";
this.left_pupil_diameter = left_pupil_diameter;
this.right_pupil_diameter = right_pupil_diameter;
}