- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Samual Sam has Published 2492 Articles
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
687 Views
Create a Calendar object.Calendar cal = Calendar.getInstance();For using above Calendar class, do not forget to import the following package.import java.util.Calendar;Now, use the getTimeInMillis() method to get the time in milliseconds.cal.getTimeInMillis()The following is the final example.Example Live Demoimport java.util.Calendar; public class Demo { public static void main(String[] args) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
3K+ Views
For using Calendar class, import the following package.import java.util.Calendar;Using the Calendar class, create an object.Calendar calendar = Calendar.getInstance();Now, create a string array of the day names.String[] days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };Display the day name.days[calendar.get(Calendar.DAY_OF_WEEK) - 1]The following is the final example.Example Live Demoimport ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
465 Views
Firstly, create a Calendar class object.Calendar calendar = Calendar.getInstance();Now, import the following package.import java.sql.Date;Using a Date class now and creating an object would belong to the above package. Convert the current time to the java.sql.Date Object.Date sqlDate = new Date((calendar.getTime()).getTime());The following is an example.Example Live Demoimport java.util.Calendar; import java.sql.Date; import java.text.ParseException; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
381 Views
To get the day of the week, use the Calendar.DAY_OF_WEEK.Firstly, let us get the current date.java.util.Date utilDate = new java.util.Date(); java.sql.Date dt = new java.sql.Date(utilDate.getTime());Now, using GregorianCalendar, set the time.java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); cal.setTime(dt);The last step would display the day of the week as shown in the following example.Example Live ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
792 Views
To display the current time in another time zone, use the TimeZone class. To use it, import the following package.import java.util.TimeZone;Firstly, set the TimeZone.cal.setTimeZone(TimeZone.getTimeZone("Europe/Sofia"));Now, display the date using the Calendar object.cal.get(Calendar.HOUR_OF_DAY) cal.get(Calendar.MINUTE) cal.get(Calendar.SECOND) cal.get(Calendar.MILLISECOND)The following is the final example.Example Live Demoimport java.util.Calendar; import java.util.TimeZone; public class Demo { public static ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
837 Views
Let’s say we have the following string.String str = "{Java is a programming language} {James Gosling developed it.}";Above, the string is enclosed with parentheses. We can split a string with these parentheses using the split() method.String[] strSplit = str.split("[{}]");The following is an example.Example Live Demopublic class Demo { public static ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
787 Views
We have the following string with two separators.String str = "Tom-Hank-s";We want the index of the first occurrence of the separator.For that, you need to get the index of the separator using indexOf()String separator ="-"; int sepPos = str.indexOf(separator);The following is an example.Example Live Demopublic class Demo { public static ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
272 Views
Let’s say we have the following string.String str = "Learning never ends! Learning never stops!";In the above string, we need to find out how many times the substring “Learning” appears.For this, loop until the index is not equal to 1 and calculate.while ((index = str.indexOf(subString, index)) != -1) { subStrCount++; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
5K+ Views
The following are our strings with single and double quote.String str1 = "This is Jack's mobile"; String str2 = "\"This is it\"!";Above, for single quote, we have to mention it normally like.This is Jack's mobileHowever, for double quotes, use the following and add a slash in the beginning as well ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
416 Views
Let’s say the following is our string.String str = "Java is a programming language. James Gosling developed it.";We will now see how to split a string using the split() method. Include the delimiter as the parameter.String[] strSplit = str.split("\.");Above, we have split the string with dot as you can see ... Read More