Karthikeya Boyini has Published 2192 Articles

SimpleDateFormat(“hh:mm:ss a”) in Java

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

The following format displays time from −hh:mm:ssThe following format displays time with AM/ PM marker −hh:mm:ss aHere, we are using the SimpleDateFormat class to display date and time. Let us set it for the format we want i.e time and AM/PM Marker −Format f = new SimpleDateFormat("hh:mm:ss a"); String strResult ... Read More

Display a percentage in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

To display a percentage in Java, use the following DecimalFormat.DecimalFormat decFormat = new DecimalFormat("#%");Since, we have used the DecimalFormat class, therefore do not forget to import the following package −import java.text.DecimalFormat;Now, let us learn how to display percentage −decFormat.format(0.80) decFormat.format(-0.19) decFormat.format(1.88)The above will be displayed as −80% -19% 188%The following ... Read More

SimpleDateFormat(“HH:mm:ss Z”) in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from theGreenwich Mean Time (GMT).Let us see the usage of SimpleDateFormat(“HH:mm:ss Z”) −Format f = new ... Read More

DecimalFormat("00.00E0") in Java

karthikeya Boyini

karthikeya Boyini

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

323 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("00.00E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("00.00E0"); System.out.println(decFormat.format(-289.8787)); System.out.println(decFormat.format(8.19));Since, we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example ... Read More

DecimalFormat("###E0") in Java

karthikeya Boyini

karthikeya Boyini

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

139 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("##E0"); System.out.println(decFormat.format(-267.9965)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88));Since we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete ... Read More

SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z') in Java

karthikeya Boyini

karthikeya Boyini

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

5K+ Views

Using the SimpleDateFormat(“E, dd MMM yyyy HH:mm:ss Z”), wherein E is for Day of Week −// displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime()));Since we have used the Format and SimpleDateFormat class above, ... Read More

MySQL concat() to create column names to be used in a query?

karthikeya Boyini

karthikeya Boyini

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

836 Views

To create column names to be used in a query, you need to use a user-defined variable with the set command. The syntax is as follows −SET @anyVariableName := (    SELECT CONCAT    (       "SELECT",    GROUP_CONCAT(CONCAT(" 1 as ", COLUMN_NAME) SEPARATOR ', '), " FROM ... Read More

Display three letter-month value with SimpleDateFormat('MMM') in Java

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

Using the SimpleDateFormat(“MMM”) to display three-letter month −Format f = new SimpleDateFormat("MMM"); String strMonth = f.format(new Date()); System.out.println("Month (Three-letter format) = "+strMonth);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

Format date with DateFormat.MEDIUM in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

DateFormat.MEDIUM is a constant for medium style pattern.Firstly, we will create date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.MEDIUM −// CHINESE dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINESE); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. MEDIUM, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; ... Read More

Formatting day of week using SimpleDateFormat in Java

karthikeya Boyini

karthikeya Boyini

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

306 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 ... Read More

Advertisements