Found 7442 Articles for Java

Format Year in yyyy format in Java

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

376 Views

To format year in yyyy format is like displaying the entire year. For example, 2018.Use the yyyy format like this −SimpleDateFormat("yyyy");Let us see an example −// year in yyyy format SimpleDateFormat simpleformat = new SimpleDateFormat("yyyy"); String strYear = simpleformat.format(new Date()); System.out.println("Current Year = "+strYear);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

Format Year in yy format in Java

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

1K+ Views

To format year in yy format is like displaying year as 01, 02, 03, 04, etc. For example, 18 for 2018.Use the yy format like this.SimpleDateFormat("yy");Let us see an example −// year in yy format SimpleDateFormat simpleformat = new SimpleDateFormat("yy"); String strYear = simpleformat.format(new Date()); System.out.println("Current Year = "+strYear);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 ... Read More

Display TimeZone in zzzz format in Java

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

359 Views

Use the zzzz format like this for TimeZone.SimpleDateFormat("zzzz");Let us see an example −// displaying timezone in zzzz format simpleformat = new SimpleDateFormat("zzzz"); String strTimeZone = simpleformat.format(new Date()); System.out.println("TimeZone in zzzz format = "+strTimeZone);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 Calendar cal = Calendar.getInstance(); ... Read More

Display TimeZone in z format in Java

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

279 Views

The z format means General Time Zone. We will use it like this.SimpleDateFormat("z");Let us see an example −// displaying timezone in z format SimpleDateFormat simpleformat = new SimpleDateFormat("z"); String strTimeZone = simpleformat.format(new Date()); System.out.println("TimeZone in z format = "+strTimeZone);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 Calendar ... Read More

Display Seconds in ss format (01, 02) in Java

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

134 Views

The ss format for seconds is like representing seconds 01, 02, 03, 04, etc. We will use it like this.SimpleDateFormat("ss");Let us see an example −// displaying seconds in ss format simpleformat = new SimpleDateFormat("ss"); String strSeconds = simpleformat.format(new Date()); System.out.println("Seconds in ss format = "+strSeconds);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

Format Seconds in s format in Java

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

181 Views

The “s” format for seconds is like representing 1, 2, 3, 4 seconds, etc. We will use it like this.SimpleDateFormat("s");Let us see an example −// displaying seconds in s format simpleformat = new SimpleDateFormat("s"); String strSeconds = simpleformat.format(new Date()); System.out.println("Seconds in s format = "+strSeconds);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

Format Month in M format in Java

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

267 Views

The “M” format is to format months i.e. 1, 2, 3, 4, etc. Here, we will use the following.SimpleDateFormat("M");Let us see an example −// displaying month with M format simpleformat = new SimpleDateFormat("M"); String strMonth = simpleformat.format(new Date()); System.out.println("Month in M format = "+strMonth);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

DecimalFormat("0000000000E0") in Java

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

88 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("0000000000E0") first.Format f = new DecimalFormat("0000000000E0");Now, we will format a number and display the result in a string using the format() method −String res = f.format(-97579.9146);Since, we have used both Format and DecimalFormat class in Java, therefore importing the following packages in a must −import java.text.DecimalFormat; import java.text.Format;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; import java.text.Format; public class Demo { public static void main(String[] argv) throws Exception { Format f = new DecimalFormat("0000000000E0"); ... Read More

DecimalFormat("000E00") in Java

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

97 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.Let us set DecimalFormat("000E00") first −Format f = new DecimalFormat("000E00");Now, we will format a number and display the result in a string using the format() method −String res = f.format(-5977.3427);Since, we have used both Format and DecimalFormat class in Java, therefore importing the following packages in a must −import java.text.DecimalFormat; import java.text.Format;The following is an example −Example Live Demoimport java.text.DecimalFormat; import java.text.Format; public class Demo { public static void main(String[] argv) throws Exception { Format f = new DecimalFormat("000E00"); ... Read More

DecimalFormat("00E00") in Java

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

125 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.Let us set DecimalFormat("00E00") first.Format f = new DecimalFormat("00E00");Now, we will format a number and display the result in a string using the format() method −String res = f.format(-5977.3427);Since, we have used both Format and DecimalFormat class in Java, therefore importing the following packages in a must −import java.text.DecimalFormat; import java.text.Format;The following the complete example −Example Live Demoimport java.text.DecimalFormat; import java.text.Format; public class Demo { public static void main(String[] argv) throws Exception { Format f = new DecimalFormat("00E00"); ... Read More

Advertisements