Import the following package for Calendar class in Javaimport java.util.Calendar;Firstly, create a Calendar object and display the current dateCalendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime());Now, let us increment the month using the add() method and Calendar.MONTH constant −calendar.add(Calendar.MONTH, 2);The following is an exampleExample Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Current Date = " + calendar.getTime()); // Incrementing Month by 2 calendar.add(Calendar.MONTH, 2); System.out.println("Updated Date (+2 Months) = " + calendar.getTime()); ... Read More
System.out.format is used in Java to format output.Firstly, create a Calendar object −Calendar calendar = Calendar.getInstance();Now, use theDate-Time conversion characters to get the date, month and year −System.out.format("%te %tB, %tY%n", calendar, calendar, calendar);The following is the complete example −Example Live Demoimport java.util.Locale; import java.util.Calendar; public class TestFormat { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.format("%te %tB, %tY%n", calendar, calendar, calendar); } }Output22 November, 2018
Sometimes while testing our app on simulator we need to test for case where no internet is available. This can be achieved in multiple ways.Below are some of the possible ways to do itEasiest but not the most correct way is to disconnect your mac from the LAN Cable is you are on a LAN, or turn off the wifi if you are connected on a wifi network. But that will definitely turn off internet for your whole device, not just simulator. So, there are some more ways to do itDownload Hardware IO tools for Xcode.Go to Xcode menu, select ... Read More
The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved) for Date and Time in JavaReference − Oracle JavaLetterDate or Time ComponentPresentationExamplesGEra designatorTextADYYearYear1996; 96YWeek yearYear2009; 09MMonth in yearMonthJuly; Jul; 07WWeek in yearNumber27WWeek in monthNumber2DDay in yearNumber189DDay in monthNumber10FDay of week in monthNumber2EDay name in weekTextTuesday; TueUDay number of week (1 = Monday, ..., 7 = Sunday)Number1AAm/pm markerTextPMHHour in day (0-23)Number0KHour in day (1-24)Number24KHour in am/pm (0-11)Number0hHour in am/pm (1-12)Number12mMinute in hourNumber30sSecond in minuteNumber55SMillisecondNumber978zTime zoneGeneral time zonePacific Standard Time; PST; GMT-08:00ZTime zoneRFC 822 time zone-800XTime zoneThe above pattern letters are combined ... Read More
Firstly, set the locale −Locale[] strLocales = { US, UK, GERMANY};Now, let us set the date formats i.e. different constants −int[] constants = { SHORT, MEDIUM, LONG }; String[] str = { "SHORT", "MEDIUM", "LONG" };Loop through and get the different date formats for different countries −for (Locale country : strLocales) { System.out.println(""+ country.getDisplayCountry() + "....."); for (int i = 0; i < constants.length; i++) { dateFormat = DateFormat.getDateInstance(constants[i], country); System.out.println(str[i] + " constant = " + dateFormat.format(dt)); } }The following is an exampleExample Live Demoimport static java.text.DateFormat.*; import static java.util.Locale.*; import ... Read More
To make our UI appealing, we have to play around with multiple attributes in iOS development. To draw shadows around a View or below a view we have to play around Layers and Views.Let’s see this in two ways.Method 1 − Simply coding where ever required.self.layer.masksToBounds = NO; self.layer.cornerRadius = 2; self.layer.shadowOffset = CGSizeMake(-5, 10); self.layer.shadowRadius = 3; self.layer.shadowOpacity = 0.3;Method 2 − Creating IBDesignable and IBInspectable and Using with Story board.@IBDesignable class DesignableView: UIView { } extension UIView { @IBInspectable var shadowRadius: CGFloat { get { return layer.shadowRadius ... Read More
In order to remove characters in a specific range from a Java StringBuffer Object, we use the delete() method. The delete() method removes characters in a range from the sequence. The delete() method has two parameters , start and end. Characters are removed from start to end-1 index.Declaration − The java.lang.StringBuffer.delete() method is declared as follows −Let us see a program to delete characters in a specific range from a Java StringBuffer Object.Example Live Demopublic class Example { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Hello World"); System.out.println("Original StringBuffer Object: " ... Read More
Firstly, set the format with SimpleDateFormat classFormat dateFormat = new SimpleDateFormat("EEE, dd/MM/yyyy");Above, the “EEE” is set to display the name of the day i.e. Monday, Tuesday, Wednesday, etc.Now, to display the date −String res = dateFormat.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String[] argv) throws Exception { Format dateFormat = new SimpleDateFormat("EEE, dd/MM/yyyy"); String res = dateFormat.format(new Date()); System.out.println("Date = " + res); } }OutputDate = Thu, 22/11/2018
The 8051 Microcontroller is designed by Intel in 1981. 8051 is 40 pin DIP IC. This is an 8-bit microcontroller.It is a very famous Microcontroller of Intel family. As we know Microprocessor like 8085, Z-80 or M6800 contains the ALU, control unit and some registers, but there were no internal storages. The Microcontroller contains the RAM and ROM, IO ports inside it. Some microcontroller also contains the ADC in it. As most of the required components are inside the chip, so the cost of application is also reduced.These kinds of microcontrollers are used in different appliances like televisions, washing machines, ... Read More
Firstly, set the time with SimpleDateFormat classFormat dateFormat = new SimpleDateFormat("h:m:s");Now, for custom format, let us fetch the hour, minute and second individuallyHour// hour dateFormat = new SimpleDateFormat("h"); String strHour = dateFormat.format(new Date()); System.out.println("Hour: "+strHour);Minute// minute dateFormat = new SimpleDateFormat("m"); String strMinute = dateFormat.format(new Date()); System.out.println("Minute: "+strMinute);Second// second dateFormat = new SimpleDateFormat("s"); String strSecond = dateFormat.format(new Date()); System.out.println("Second: "+strSecond);The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String[] argv) throws Exception { Format dateFormat = new SimpleDateFormat("h:m:s"); String str = dateFormat.format(new Date()); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP