Java:设置java.SQL.Timestamp的时间部分而不更改日期

时间:2016-11-03 10:17:30

标签: java timestamp

我正在开发一个Java项目,其中我在另一列中有一个Time对象。但是出于某些查询目的,我需要将时间作为时间戳的一部分。出于这个原因,我决定调用java.SQL.Timestamp的setTime方法,但它将日期重置为1970.

我怎样才能只更改java.SQL.Timestamp中的时间部分?

COde:

            object.getTimestamp().setTime(object.getTTime().getTime());

谢谢。

1 个答案:

答案 0 :(得分:2)

使用普通@ECHO off SET "dirWhereKept=%1" SET mp4=".mp4" SET mkv=".mkv" SET avi=".avi" SET needCompressingDir="E:\Need_compressing" SET minimumSize=200 CD %needCompressingDir% CD %dirWhereKept% FOR /f "delims=" %%i IN ('DIR /B') DO ( IF EXIST "%%~i\" ( rem do nothing ) ELSE ( GOTO :EOF CALL :checkIfWantedFile "%%i" "%%~xi" "%%~zi" ) ) :checkIfWantedFile SET file=%~1 SET fileExtension=%~2 SET fileSizeInBytes=%~3 IF "%fileExtension%" == %mp4% ( CALL :checkFileSize %fileSizeInBytes% ) ELSE ( IF "%fileExtension%" == %mkv% ( CALL :checkFileSize %fileSizeInBytes% ) ELSE ( IF "%fileExtension%" == %avi% ( CALL :checkFileSize %fileSizeInBytes% ) ELSE ( rem this is not required! CALL :deleteFile ) ) ) :checkFileSize SET /a fileSizeInMB=%~1/1024/1024 IF %fileSizeInMB% GTR %minimumSize% ( CALL :moveFileToCompress ) :deleteFile ECHO "Delete called!" :moveFileToCompress MOVE %file% %needCompressingDir% 工作,使用java.util.Date更新时间部分,然后使用

更新时间戳
Calendar

实施例

  setTime(long time) 

修改

示例2

            Calendar c=Calendar.getInstance();
    c.setTimeInMillis(time.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    ts.setTime(c.getTimeInMillis());
    System.out.println(ts.getTime());