Convert Instant to LocalDateTime in Java

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

608 Views

Let’s say you need to convert Instant to LocalDateTime with IST with timezone:Create an Instant:Instant instant = new Date().toInstant();Now, convert Instant to LocalDateTime:LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("IST")));Exampleimport java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Instant instant = new Date().toInstant();       LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("IST")));       System.out.println("Date (IST) = " + date);       date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("PST")));       System.out.println("Date (PST) = " + date);       date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("EST")));       System.out.println("Date (EST) = " ... Read More

Change File Extension in Text Column in MySQL

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

473 Views

To change the file extension in the text column, you can use UPDATE command along with REPLACE() function. Let’s say we have some columns with extensions and we need to replace all of them. For that, let us first create a table with the extension columns set as text type:mysql create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProgramExtension1 text,    ProgramExtension2 text,    ImageExtension text ); Query OK, 0 rows affected (0.52 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable(ProgramExtension1, ProgramExtension2, ImageExtension)values('.java', '.c', '.jpeg'); Query OK, ... Read More

FloatBuffer wrap Method in Java

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

175 Views

A float array can be wrapped into a buffer using the method wrap() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       try {          float[] arr = { 8.7F, 1.5F, 3.2F, 7.4F, 5.9F ... Read More

I/O Mapped I/O in 8085 Microprocessor

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

5K+ Views

Generally, a processor like 8085, to address one I/O port by sending out 8-bit port address and IO/M* = 1. For example, let us say, the chip select pin of an I/O port chip is activated when 8-bit address = F0H, IO/M* = 1, and RD* = 0. This is shown in the following fig.Such I/O ports, which are addressed by the processor by sending out IO/M* as logic 1 are called I/O-mapped I/O ports.An Input Output port is generally addressed by 8085 Processor by releasing the port address of 8-bit and IO/M* = 1. An example to be cited ... Read More

Use a Filter in JSP

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

701 Views

Following example shows how to print the client's IP address and the current date time, each time it would access any JSP file. This example will give you a basic understanding of the JSP Filter, but you can write more sophisticated filter applications using the same concept −// Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Implements Filter class public class LogFilter implements Filter {    public void init(FilterConfig config) throws ServletException {       // Get init parameter       String testParam = config.getInitParameter("test-param");       //Print the init parameter ... Read More

Use Contains in Android TextView

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

1K+ Views

This example demonstrate about How to use contains () in Android text view.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             In the above code, we have taken name as Edit text, when user click on button it will take data and compare with tutorialspoint string.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; ... Read More

MonthDay compareTo Method in Java

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

183 Views

Two MonthDay objects can be compared using the compareTo() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be compared.If the first MonthDay object is greater than the second MonthDay object it returns a positive number, if the first MonthDay object is lesser than the second MonthDay object it returns a negative number and if both the MonthDay objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = ... Read More

Duration minusHours Method in Java

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

100 Views

An immutable copy of a duration where some hours are removed from it can be obtained using the minusHours() method in the Duration class in Java. This method requires a single parameter i.e. the number of hours to be subtracted and it returns the duration with the subtracted hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(6);       System.out.println("The duration is: " + d);       System.out.println("A copy with 4 hours removed from the duration is: ... Read More

Loop Through a Stored Procedure in MySQL

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

284 Views

Let us see how to loop through a stored procedure in MySQLmysql> DELIMITER // mysql> CREATE PROCEDURE do_WhileDemo(LastValue INT)    -> BEGIN       -> SET @loop = 0;       -> REPEAT          -> SET @loop= @loop+ 1;          -> select @loop;          -> UNTIL @loop >LastValue       -> END REPEAT;    -> END // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;Now call the stored procedure with the help of CALL command.The query is as followsmysql> call do_WhileDemo(10);The following is the output+-------+ | ... Read More

Ignoring the Year in MySQL Query with Date Range

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

712 Views

To ignore the year with date range, use the DATE_FORMAT() with the between clause. Let us first create a demo table. The query to create a table is as follows −mysql> create table igonreYearDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ShippingDate date    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into igonreYearDemo(ShippingDate) values('2016-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into igonreYearDemo(ShippingDate) values('2018-01-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

Advertisements