Samual Sam has Published 2310 Articles

Display year with SimpleDateFormat('yyyy') in Java

Samual Sam

Samual Sam

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

558 Views

Using the SimpleDateFormat(“yyyy”) to display year −// displaying year Format f = new SimpleDateFormat("yyyy"); String strYear = f.format(new Date()); System.out.println("Year = "+strYear);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The ... Read More

Java Program to copy an array from the specified source array

Samual Sam

Samual Sam

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

176 Views

Use arraycopy() method in Java to copy an array from the specified source array.Here, we have two arrays −int arr1[] = { 10, 20, 30, 40}; int arr2[] = { 3, 7, 20, 30};Now, we will use the arraycopy() method to copy the first two elements of the 1st array ... Read More

Java Program to format date in mm-dd-yyyy hh:mm:ss format

Samual Sam

Samual Sam

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

8K+ Views

Let us format date in mm-dd-yyyy hh:mm:ss format −// displaying date in mm-dd-yyyy hh:mm:ss format Format f = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss"); String str = f.format(new Date()); System.out.println("Current Date in MM-dd-yyyy hh:mm:ss format = "+str);Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, ... Read More

Empty string in not-null column in MySQL?

Samual Sam

Samual Sam

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

3K+ Views

In PHP, the empty string equals to a NULL value, but in MySQL, the case is the different i.e. empty string is not equal to NULL value. To understand the above syntax, let us create a column with NOT NULL constraint while you can insert an empty string.Let us create ... Read More

Formatting day of week in EEEE format in Java

Samual Sam

Samual Sam

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

3K+ Views

EEEEE format is used in Java Date to format day of week like Monday, Tuesday, Wednesday, etc. Let us use it −// displaying day of week SimpleDateFormat simpleformat = new SimpleDateFormat("EEEE"); String strDayofWeek = simpleformat.format(new Date()); System.out.println("Day of Week = "+strDayofWeek);Above, we have used the SimpleDateFormat class, therefore the following ... Read More

Search for text between delimiters in MySQL?

Samual Sam

Samual Sam

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

655 Views

You need to use LOCATE() along with SUBSTR(). The below syntax will find the word after delimiter. Here, delimiter is colon(:), you can use another i.e. it is up to you. The syntax is as follows −SELECT SUBSTR(yourColumnName, LOCATE(':', yourColumnName)+1, ... Read More

Apply modulus operator to floating-point values in Java

Samual Sam

Samual Sam

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

758 Views

To apply modulus (%) operator to floating-point values in an effortless task. Let us see how.We have the following two values −double one = 9.7; double two = 1.2;Let us now apply the modulus operator −one % twoThe following is the complete example that displays the output as well −Example Live ... Read More

Java program to print the initials of a name with last name in full

Samual Sam

Samual Sam

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

10K+ Views

When the full name is provided, the initials of the name are printed with the last name is printed in full. An example of this is given as follows −Full name = Amy Thomas Initials with surname is = A. ThomasA program that demonstrates this is given as follows −Example Live ... Read More

Formatting day in dd format in Java

Samual Sam

Samual Sam

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

486 Views

The dd format in Java Date is like 05, 06, 07, 08, 09, etc. i.e. with two-letter digit. Let us use it.// displaying day in dd format SimpleDateFormat simpleformat = new SimpleDateFormat("dd"); String strDay = simpleformat.format(new Date()); System.out.println("Day in dd format = "+strDay);Above, we have used the SimpleDateFormat class, therefore ... Read More

Display hour in hh (01-12 in AM/PM) format in Java

Samual Sam

Samual Sam

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

415 Views

The “hh” format in Java Date is like 01 – 12 hour in AM/ PM. Use SimpleDateFormat("hh") to get the same format;// displaying hour in hh format SimpleDateFormat simpleformat = new SimpleDateFormat("hh"); String strHour2 = simpleformat.format(new Date()); System.out.println("Hour in hh format = "+strHour2);Above, we have used the SimpleDateFormat class, therefore ... Read More

Advertisements