Handling multiple timezone in Java [closed] - java

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 6 years ago.
Improve this question
I need to store multiple user details from different country. How can I store the dates in DB (in UTC format) and how can I show the dates to the users accorning to their time zones.
I am using Java and mySQL.

In MySQL, use the TIMESTAMP data type in your tables.
For each user, store a timezone column, VARCHAR(64) is a good data type for that column. When a user registers to use your system, ask for the time zone value. Mine is America/New_York. Yours might or might not be Asia/Kolkata. For a user interface for this user-preference setting, the WordPress.org software has a good example.
Finally, whenever you establish a connection from your Java program to your DBMS in behalf of a user, issue the SQL command
SET SESSION time_zone='(whatever tz string the user gave you)'
before you handle any user data.
This will cause all times going in to your tables to be converted to UTC, and all times coming out to be translated to local. It works properly for NOW() and CURDATE(). Again, you must use TIMESTAMP and not DATETIME or DATE data types for this.
Make sure your server OS and default MySQL time zones are set to UTC. If you don't do this before you start loading information into your database, it will be almost impossible to fix. If you use a vendor to run MySQL, insist they get this right and fire the vendor if they don't have it right.

Related

Retrieving new oracle table records on insert to process in Java client application [closed]

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 13 days ago.
Improve this question
I am trying to retrieve the new inserts from a table in my java client application (Spring JMS), to do some processing and send them to a message broker. I do not have access to any CDC tool like Goldengate. I only need the new inserts and not the updates or deletes. I am having difficulty finding a way to do this. Is there a way to do this? I read that there is an option to do these with triggers, but will it have a high throughput on the db, because this table gets a lot of inserts in a day (approximately around 50K records inserted in a day).
Thanks in advance
50,000 rows per day is actually rather a low volume. Some data warehouse tables get 50 million rows a day. So an insert trigger is unlikely to make any appreciable difference on the loading job. Add a date column (e.g. LOAD_DATE) and have a before insert trigger assign :new.LOAD_DATE := SYSDATE.
That being said, if you wanted to avoid a trigger, you can modify the loading job itself to load such a date a column with SYSDATE.
With either method, your retrieval is then simple: each day as you retrieve records, record the maximum LOAD_DATE value you retrieved. The next day, pull only records with a LOAD_DATE >= that value.

Sending an email at a specific time using spring boot [closed]

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 6 months ago.
Improve this question
in the application I am developing I can specify an expiration date of a license and now I want to create an a java spring boot api that can send an email to a specific email before a specific time period (the user can choose the time period). The purpose of the email is to notify the user that his license is about to end.
For example:
The user chooses an expiration date of 3/8/2023 and chooses to be notified 3 months before the expiration date chosen. An email gets sent to the user's email on 3/5/2023 notifying the user that the license is about to end.
Any help is highly appreciated.
You need to store the info in database. So that your system knows when to send the email. For ex, having two columns in a table like send_notif_date, send_to_user.
write a job(you can use Quartz for this) which will pick all details of user for which we need to send the emails based on if today equalsTo send_notif_date

Good practices with java.time - how to represent datetime in my dto/entity/model classes? [closed]

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.

Firebase Event Logging offline and online in Android [closed]

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 3 years ago.
Improve this question
If I log events offline and then send them online in a bulk to Firebase then, will the event date be the same as the date of sending or logging?
Neither Cloud Firestore nor Firebase Realtime Database does not have the date and time stored in the metadata. If you need this feature, you should add a timestamp property for each document/node separately. That actually represents a FieldValue.serverTimestamp() in case of Cloud Firestore and a ServerValue.TIMESTAMP in case of Firebase Realtime Database.
Please also bear in mind that both types of timestamps are generated on the server. In the case of Cloud Firestore it's a Date object, and in case of Firebase Realtime Database is a long value which represents the time since the Unix epoch, in milliseconds.
If you have this kind of property present in your database and you set/modify it once an object is added/changed, then the date and time of that property is the date and time when the device comes back online since the timestamp is generated entirely by Firebase servers. And to answer your question:
will the event date be the same as the date of sending or logging?
It will be the time of sending and not logging.

24h time after midnight order [closed]

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
I'm facing this problem. When I wrap times from websites I'm always getting a 0:00h or 0:30h for example. This is technically at the beginning of the current date. But for humans is at the end of current date.
I need 0:00 to 6:00 get sorted at the end of the day instead of beginning, directly from data-base.
I'm using java, hibernate criteria, mysql datetime.
Thanks all!
You can get your dates and times ordered correctly by using MySql DATETIME data types throughout your application. The Java equivalent class is util.Date.
According to computer and telecommunications industry standards, the first millisecond of each calendar day has the time 00:00.000. So, if you add ten seconds to 23:59:51.000 you get 00:00:01.000 on the next day.
It sounds like your business has a different, non-standard, rule for describing the beginning and ending of each day, to use for this particular display. That's fine. But you need to enumerate this rule very precisely indeed. Midnight matters in many fields of human endeavor!
Let's say your rule is that a day's information runs from [01:00:00 to 01:00:00) the next day.
Then you can select yesterday's records in a MySQL query like this.
WHERE `timestamp` >= CURDATE() - INTERVAL 1 DAY + INTERVAL 1 HOUR
AND `timestamp` < CURDATE() + INTERVAL 1 HOUR
...
ORDER BY `timestamp`
This will display your stuff in the right order. It won't display the time 24:01, but it will place 00:01 after 23:59.

Categories

Resources