Samual Sam has Published 2492 Articles

Java Program to get the difference between two time zones by seconds

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

719 Views

Here are the two timezones −ZoneId zone1 = ZoneId.of("America/Panama"); ZoneId zone2 = ZoneId.of("Asia/Taipei");Set the date −LocalDateTime dateTime = LocalDateTime.of(2019, 04, 11, 10, 5);Now, set the first timezone −ZonedDateTime panamaDateTime = ZonedDateTime.of(dateTime, zone1);Set the second timezone −ZonedDateTime taipeiDateTime = panamaDateTime.withZoneSameInstant(zone2);Get the timezone differences in seconds −taipeiDateTime.getOffset().getTotalSeconds()Exampleimport java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; ... Read More

How do I add a value to the top of an array in MongoDB?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

153 Views

To add a value to the top of an array in MongoDB, you can use unshift() −yourArrayName.unshift("yourValue");The above syntax will add the value to the top of an array in MongoDB. Let us first create an array of strings −> technicalSkills=["Java", "MySQL", "C", "SQL SERVER", "ORACLE", "PL/SQL"];This will produce the ... Read More

Get total number of rows while using LIMIT in MySQL?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

989 Views

To get the total number of rows when using LIMIT, use the following syntax −select SQL_CALC_FOUND_ROWS * FROM yourTableName LIMIT 0, yourLastValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table RowsUsingLimit -> ( ... Read More

Java 8 Clock offset() method

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

91 Views

The fixed instant on the clock can be obtained using the method fixed() in the Clock Class in Java. This method requires two parameters i.e. the fixed instant and the time zone. Also, it returns the fixed instant on the clock. The fixed() method is normally used for testing purposes.A ... Read More

Iterate through Triplet class in JavaTuples

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

208 Views

The iteration in Triplet class works in the same way as Arrays collection.Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import the following package −import org.javatuples.Triplet;Note − Steps to download and run JavaTuples program If you are ... Read More

How to print date and time in specific format using JSP?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

1K+ Views

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.Let us modify the above example as follows −Example Live Demo           Display Current Date & Time     ... Read More

Duration ofMinutes() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

83 Views

The duration can be obtained in a one minute format using the ofMinutes() method in the Duration class in Java. This method requires a single parameter i.e. the number of minutes and it returns the duration in a one minute format. If the capacity of the duration is exceeded, then ... Read More

How to update the column of a row in a CachedRowSet object in JDBC?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

483 Views

The CachedRowSet is the base implementation of disconnected row sets. It connects to the data source, reads data from it, disconnects with the data source and the processes the retrieved data, reconnects to the data source and writes the modifications.You can create a Cached RowSet object using the createCachedRowSet() method ... Read More

Extract subarray value in MongoDB?

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

360 Views

To extract the subarray value in MongoDB, you can use $elemMatch projection operator.Let us first create a collection with documents −> db.extractSubArrayDemo.insertOne( ...    { ...       _id: 101, ...       "clientName":"Larry", ...       "ClientDetails": ...       [ ...       ... Read More

Duration toHours() method in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:25

124 Views

The value of a duration in the form of a number of hours can be obtained using the method toHours() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of hours.A program that demonstrates this ... Read More

Advertisements