How to get current date and time in Java (modern ways)
Hello everyone! I just started learning Java and encountered what seems like a simple task: I need to get the current date and time in a program. For example, I'm writing a small note-taking application and I want each note to automatically save a timestamp — the moment it was created.\n\nI googled it and found a bunch of different options: `new Date()`, `System.currentTimeMillis()`, `Calendar.getInstance()`. I tried `new Date()` — it seems to work, but it outputs something strange like "Fri Jan 10 14:23:05 MSK 2025". But I need, for example, "10.01.2025 14:23:05" or "2025-01-10T14:23:05".\n\nThen I read that the old `Date` and `Calendar` classes are considered deprecated and not recommended for use. Apparently, Java 8 introduced a new API for working with dates. But how do I use it? I tried to write
No answers yet.
Log in to leave an answer
Blogs