yk3125さん、
以下のようにすると、時間の設定ができるようです。
//Filename: DateSetTest.java
import java.io.IOException;
public class DateSetTest {
public static void main(String[] args) throws IOException {
System.out.println("DateSetTest!");
String[] cmd = {"sudo","date","-s","2020/03/21 22:00:00"};
Process pb = Runtime.getRuntime().exec(cmd);
}
}
pi@raspberrypi:~ $ export TZ=JST
pi@raspberrypi:~ $ javac DateSetTest.java && java DateSetTest && date
DateSetTest!
Sat 21 Mar 2020 10:00:00 PM JST
pi@raspberrypi:~ $
- 実行環境
- Raspberry Pi 4B (2GB)
- Raspbian: 2020-02-13-raspbian-buster ベースで、sudo apt update && sudo apt upgrade -y
- JDK: sudo apt install default-jdk -y にてインストール
pi@raspberrypi:~ $ java --version
openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.6+10-post-Raspbian-1deb10u1, mixed mode)
pi@raspberrypi:~ $