Formatting Day of Week Using SimpleDateFormat in Java

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

296 Views

E format is used in Java Date to format day of week like Mon, Tue, Wed, etc. Let us use it.// displaying day of week SimpleDateFormat simpleformat = new SimpleDateFormat("E"); String strDayofWeek = simpleformat.format(new Date()); System.out.println("Day of Week = "+strDayofWeek);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

Parse Date in MySQL

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

2K+ Views

Parse date in MySQL with the help of STR_TO_DATE() function. The syntax is as follows −select str_to_date(yourColumName, ’format’) as anyVariableName from yourTableName;The format in the above syntax is '%d-%b-%y'.Now to understand the above function, let us create a table. The following is the query to create a table −mysql> create table ParseDateDemo −> ( −> yourDate varchar(200) −> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table with the help of select statement. The query is as follows −mysql> insert into ParseDateDemo values('10-Nov-18'); Query OK, 1 row ... Read More

Using OR with Multiple MySQL LIKE Statements

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

154 Views

You can OR two like statements using the following syntax −SELECT *FROM yourTableName WHERE (yourColumnName like '%yourValue1%' OR yourColumnNamelike '%yourValue2%') AND yourColumnName = yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ORLikeDemo    -> (    -> Id int not null auto_increment,    -> FirstName varchar(15),    -> LastName varchar(15),    -> Primary Key(Id)    -> ); Query OK, 0 rows affected (1.19 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ORLikeDemo(FirstName, LastName) values('John', 'Smith'); Query OK, ... Read More

Latest Electronic Home Decor Devices

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

290 Views

Home is where the heart is! And one feels like calling a house as a home if the home is well decorated or is made attractive using flowers or fragrances that please the senses. But, gone are the days when only flowers or bonsai plants could decorate home. The latest trend is the use of electronic devices for home decor.Some of them areClocks: Clocks were used earlier just to note the time. But, these have actually become a luxury symbol now. Not only the brand makes it look costly, but also the design. The other day, I went to a ... Read More

Use a Character Class in Java Regular Expressions

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

177 Views

A character class is set of characters that are enclosed inside square brackets. The characters in a character class specify the characters that can match with a character in an input string for success. An example of a character class is [a-z] which denotes the alphabets a to z.A program that demonstrates a character class in Java Regular Expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("[a-z]+");       Matcher m = p.matcher("the sky is blue");       System.out.println("The input ... Read More

Improve MySQL Search Performance with Wildcards

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

457 Views

No, MySQL won’t improve search performance whenever you have leading wildcards because MySQL will be unable to use the index. If you change to ‘anyLetter%’ then it will be able to use indexThe below syntax is better to use with trailing wildcards. The syntax is as follows −SELECT *FROM yourTableName WHERE yoorColumnName LIKE ‘anyLetter%’;The query to create a table is as follows −mysql> create table TrailingWildCardDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name Varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 ... Read More

Formatting Day of Week in EEEE Format in Java

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 package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

Difference Between a Simile and a Metaphor

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

603 Views

Poems are different and similar in the manner and matter they possess. The manner in which a poet expresses his ideas deal with literary devices such as simile, metaphor, hyperbole, contrast, repetition, imagery etc. Both simile and metaphor are used as comparative literary devices.Comparison Between Simile and MetaphorSimile - Similes are used to compare attributes of two objects or persons using words like or as. It must be noted that use of like or as always does not imply the presence of a simile. What is important is a direct comparison taking place.For Example,  Her cheeks are red as a rose.In ... Read More

Working with Matcher end() Method in Java Regular Expressions

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

154 Views

The offset value after the last character is matched from the sequence according to the regex is returned by the method java.util.regex.Matcher.end(). This method requires no arguments. If no match occurs or if the match operation fails then the IllegalStateException is thrown.A program that demonstrates the method Matcher.end() Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("(a*b)");       Matcher m = p.matcher("caaabccaab");       System.out.println("The input string is: caaabccaab");       System.out.println("The Regex is: (a*b)");   ... Read More

Return Hexadecimal Value of Byte Array in Java

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

153 Views

The following is the supplied byte array −byte[] b = new byte[]{'x', 'y', 'z'};We have created a custom method “display” here and passed the byte array value. The same method converts byte array to hex string −public static String display(byte[] b1){    StringBuilder strBuilder = new StringBuilder();    for(byte val : b1){     strBuilder.append(String.format("%02x", val&0xff)); } return strBuilder.toString(); }Let us see the entire example now −Example Live Demopublic class Demo { public static void main(String args[]) { byte[] b = new byte[]{'x', 'y', ... Read More

Advertisements