2016-08-05 7 views
2

ich habe folgenden Batch-Datei-Java-Code, ich möchte hinzufügen, Datum Zeit auch in mylog.txt jemand mir helfen, ich weiß nicht, wie man datetime mit Sekunden in Java Batch.wie man datetime in mylog.txt file java

@echo off 
cd "C:\TreasureCliServices\" 
start TreasureCliServiceCmd.exe 

set JAVA_HOME=C:\jdk1.5.0_05 

set CLI_HOME=c:\projects\utds\applications\cli 
set CLI_LIB=%CLI_HOME%\lib 

set CLASSPATH=%CLI_LIB%\commons-logging.jar;%CLI_LIB%\commons-logging-api.jar 
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\spring.jar;%CLI_LIB%\spring-core.jar;%CLI_LIB%\spring-support.jar;%CLI_LIB%\spring-remoting.jar 
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\utds-infra.jar;%CLI_HOME%\src\conf\spring;%CLI_HOME%\src\conf 
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\aopalliance.jar 
set CLASSPATH=%CLASSPATH%;%CLI_HOME%\dist\cli.jar;%JAVA_HOME%\jre\lib\ext\comm.jar 

set path=%JAVA_HOME%\bin;%path% 

java -Dport=COM3 -DbaudRate=9600 -Dparser=lgCliParser -DappContext=applicationContext-service.xml com.utds.cli.service.comm.CallerIdListener > mylogs.txt 

java -Dport = COM3 -DbaudRate = 9600 -Dparser = lgCliParser -DappContext = application-service.xml com.utds.cli.service.comm.CallerIdListener> mylogs.txt

diese Zeile Rückkehr speichern unter Daten in Textdatei, ich möchte aktuelle datetimewith Sekunden auch

got message '001 : 1234567885' got message '001 : 1234567885 -> 101' {phoneNo=1234567885, handsetId=101} 
+0

Es gibt% date% und% time% Umgebungsvariablen. – Squashman

+0

wie Sie datetime –

+0

hinzufügen müssen Sie genauer als das sein. Bitte bearbeiten Sie Ihre Frage und geben Sie ein Beispiel dafür, was Sie als Ausgabe benötigen. – Squashman

Antwort

0
@echo off 

set Year=%DATE:~10,4% 
set Month=%DATE:~4,2% 
set Day=%DATE:~7,2% 

set Hour=%TIME:~0,2% 
set Minute=%TIME:~3,2% 
set Second=%TIME:~6,2% 

rem Modify this line to fit your time format 
set CurrentTime=%Year%-%Month%-%Day%_%Hour%_%Minute%_%Second% 

echo %CurrentTime% 

pause 

rem > will simply overwrite the log file 
echo (%CurrentTime%) java -Dport=COM3 -DbaudRate=9600 -Dparser=lgCliParser -DappContext=applicationContext-service.xml com.utds.cli.service.comm.CallerIdListener > mylogs.txt 
rem >> will append to the log file 
echo (%CurrentTime%) java -Dport=COM3 -DbaudRate=9600 -Dparser=lgCliParser -DappContext=applicationContext-service.xml com.utds.cli.service.comm.CallerIdListener >> mylogs.txt 

pause 

hoffe, es hilft