A
A
Andrey Shishkin2015-11-05 18:20:53
Java
Andrey Shishkin, 2015-11-05 18:20:53

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

8 answer(s)
A
Andrey Shishkin, 2015-11-05
@compiler

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!

C
Chvalov, 2015-11-05
@Chvalov

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()));
    }
}

At the exit:
Текуще время: 17:40:07
Дата: 2015.05.11Время: 17:40:07 Часовой пояс: +02День недели: 4
Дата: 2015.05.11Время: 17:40:07 Часовой пояс: +02День недели: 4

UPD : So then:
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();
        }
    }
}

T
TomasHuk, 2013-10-16
@artishok

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.

R
Roman Misyurev, 2013-10-16
@Sudo

www.staffcop.ru/home/

M
mrakolice, 2013-10-17
@mrakolice

www.rescuetime.com

Z
zednight, 2013-10-18
@zednight

Hamster - under Linux if.

A
Asperong, 2013-11-21
@Asperong

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

S
sasa13e, 2014-04-14
@sasa13e

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 question

Ask a Question

731 491 924 answers to any question