Answer the question
In order to leave comments, you need to log in
How to get the time set directly on the computer?
The time received via new Date() or LocalDateTime.now() is one hour later than the current time on the computer. What's wrong ?
OS: corporate Windows 7 with all updates, in the domain. Java version - 1.8.0_25.
Answer the question
In order to leave comments, you need to log in
The default time zone is returned - "Europe/Moscow", in the system parameters (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2).
It feels like java returns UTC+4
UDP: The problem was solved here javatalks.ru/topics/35236 and here stackoverflow.com/questions/7066075/jvm-and-timezones
Squeeze:
The problem is that jre incorrectly determines the system time zone.
Solution:
when starting the program, pass the key -Duser.timezone=GMT+3 or use the following code:
TimeZone.setDefault(TimeZone.getTimeZone("GMT+3"));
Helped me. I mark it as a solution!
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println("Текуще время: " + sdf.format(cal.getTime()) );
DateFormat df = new SimpleDateFormat("Дата: " + "yyyy.dd.MM" + "Время: " + "HH:mm:ss " + "Часовой пояс: X" + "День недели: u" ); //Формируем строку для вывода
Date dateobj = new Date();
System.out.println(df.format(dateobj));
//Текущее время с использованием класса calendar
Calendar calobj = Calendar.getInstance();
System.out.println(df.format(calobj.getTime()));
}
}
Текуще время: 17:40:07
Дата: 2015.05.11Время: 17:40:07 Часовой пояс: +02День недели: 4
Дата: 2015.05.11Время: 17:40:07 Часовой пояс: +02День недели: 4
import java.io.*;
public class Main {
public static void main(String[] args) {
String command = "cmd /c time";
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
There is a good program MotivateClock . I've been using it for a long time, I'm happy with it. As for the messenger, it probably will not determine who you are communicating with, it will simply record how much time you spent in it. It summarizes information by projects, by days, by sites, etc. There are reports.
An option for real professionals))) OfficeMETRIKA http://office-metrika.ru/
clearly captures what you were doing at the computer, programs, messenger sites. Then all these statistics can be viewed in different types of charts, in pie charts, columns, etc.
Plus, the program separates the activity by form: by pressing keys, scrolling the mouse, moving the mouse. And it will immediately become clear: in Worde you were doing business, or dreaming, moving your mouse.
Trust me, it's motivating
For manual control, there is a wonderful online resource toggl.com . There are linux, windows, macos, android, ios applications, and of course a web interface. All the free features are enough for me alone, but if you want, for $ 5 a month you get all sorts of unnecessary goodies.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question