Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If I have a date supplied to a system written in Java, is there any way of telling if it is GMT or BST?
For formatting, you should really use a DateFormat implementation (e.g. SimpleDateFormat). That will let you specify the time zone (and output format).
Ultimately, you need to post code so we know what a "date supplied to a system" looks like.
It can always be identified. (EDIT: Unless you just got a string, like you did.)
There's something like this if you're interested in a TimeZone class.
Use those proper DateFormat Java Docs. Answer your own questions, then ask the ones you can't answer. That's what SO is for.
The Date class is timezone dependent.
One google search prevents a duplicate like this.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
In a Java project, I get the date using the method:
LocalDateTime.now() // 2023-02-19T00:52:49.177123900
This is the correct date.
I insert this date into the database.
If you look at this date in the database, it will be different:
2023-02-18 13:52:49.177124
This is not the correct date.
Why does this happen and how can I fix it?
MySql server shows the correct time, the same as the LocalDateTime.now() method.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 21 days ago.
Improve this question
I was having a look at 1.19 MCP, which I downloaded from their GitHub, when I found something strange. In the file net.minecraft.world.damagesource, the class DamageSource contains two variables, among others, that look exactly the same.
These are the declarations:
public static final DamageSource IN_FIRE = (new DamageSource("inFire")).bypassArmor().setIsFire();
public static final DamageSource ON_FIRE = (new DamageSource("onFire")).bypassArmor().setIsFire();
Does anyone know why both variables are very similar? What is the difference between them? Where is one used and where is the other one used?
I tried looking online and trying to follow the implementations of both variables, but so far no good.
Judging from the names, the one might be damage due to the player walking in fire and the other due to the player having caught fire, or in other words, being on fire.
As #Sweeper has pointed out in the comments, the distinction is required, for example, to give precise death messages.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
For simplicity let's assume we're talking about a classic web application that has backend written in Java, has a SQL database and communicates through REST.
My question is: What is the best java.time class to represent some point in time (e.g. time when a comment was posted) in a data structure-like class (DTO, JPA Entity, Model)? I've already seen it all: LocalDateTime, ZonedDateTime, Date, Instant. Especially LocalDateTime as a field in JPA Entity just doesn't feel right. What should be used? ZonedDateTime? OffsetDateTime? Instant? "Good" old java.util.Date and convert it into some java.time object only when some date calculations are needed?
An unambiguous, unmoving point in history is always correctly represented as an Instant, which is a point in physical time.
In your scenario, it might particularly make sense for this Instant to appear differently depending on the time zone of the person who asked: for example, if the comment was posted five minutes ago, any user looking at that comment should see a time that is five minutes before their local time.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm not sure is this right place to ask so correct me if I'm wrong.
The case is that:
one category has one code
we want to get list of codes for multiple categories
Which version is correct and why?
getCategoriesCodes()
or
getCategoryCodes()
I see this problem from two points of view, one is the English grammar, and the second one is the clean code and code meaningful naming.
Please give me your opinion which method name is better and add note is English you native language.
As both a native English speaker and a Java programmer: getCategoryCodes() is preferable. getCategoriesCodes() implies to me that I am getting multiple codes for each category, or that the codes relate to the collection of categories, rather than a code for each category.
As an example from "real" English: a car has one driver; you would refer to the drivers of many cars as "car drivers", not "cars drivers".
I would side with the clean code and meaningful naming. Nobody will judge your English in your code and also looking at the code in a month or a year will make it easier to understand if its worded correctly
There is no harm in giving names grammatical correct provided it is readable and understandable and not become very long because long names are difficult to understand.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm creating an app, which can show the times of different cities. I have an api which takes coordinates and gives me something like - America/Chicago. But I want to show this on a Digital Clock. Can someone please tell me how to change the timezone of a DigitalClock, or make a custom one. I have no clue! Thanks for the help!
Android: DigitalClock remove seconds
customized digital clock in android
I assume you can then work out how much time to add/subtract from the system's time to show the destination's time.
Do you mean by like a digital clock as in a widget? You're going to need to give more information about it.
You can try doing a textview in an activity and set it to change every minute or hour by getting the time from this class
from Android API.