Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java calendar

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateAndCalendar {
	public static void main(String[] argv) throws ParseException {

		//1. Create a Date from String
		SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
		String dateInString = "22-01-2015 10:20:56";
		Date date = sdf.parse(dateInString);
                DateAndCalendar obj = new DateAndCalendar();

		//2. Test - Convert Date to Calendar
		Calendar calendar = obj.dateToCalendar(date);
		System.out.println(calendar.getTime());
		
		//3. Test - Convert Calendar to Date
		Date newDate = obj.calendarToDate(calendar);
		System.out.println(newDate);

	}

	//Convert Date to Calendar
	private Calendar dateToCalendar(Date date) {

		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;

	}

	//Convert Calendar to Date
	private Date calendarToDate(Calendar calendar) {
		return calendar.getTime();
	}

}
Comment

java calendar

// Date getTime(): It is used to return a
// Date object representing this
// Calendar's time value.
  
import java.util.*;
public class Calendar1 {
    public static void main(String args[])
    {
        Calendar c = Calendar.getInstance();
        System.out.println("The Current Date is:" + c.getTime());
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: return two values in java 
Java :: how to check number of messages in kafka topic 
Java :: BodyContentImpl memory leak 
Java :: a?che les paramètres de la ligne de commande triés par ordre lexicographique en java 
Java :: how to replace in java 
Java :: constructor in java 
Java :: how to add arms to armor stands 1.16 Java Edition 
Java :: change text size java 
Java :: debug cxf 
Java :: framboise bleue ou mure 
Java :: generate random number in java within a range without repeating with android studio 
Java :: hasNext for scanner class java 
Java :: how to return arraylist as array in java 
Java :: hdfs hadoop JobClient.java:876 error 
Java :: Java display form 
Java :: Delete Specials Caractères from a String in java 
Java :: how to create a subclass in java 
Java :: split string into array java 
Java :: arraylist<hashmap<string, string arraylist = new arraylist<() 
Java :: flutter webview plugin background transparent 
Java :: split on . in java 
Java :: map.keyset 
Java :: has been compiled by a more recent version of the Java Runtime (class file version 55.0) 
Java :: java regular expressions 
Java :: javaparser 
Java :: spring-boot-maven-plugin not found 
Java :: measure view height android 
Java :: java file search recursive 
Java :: how to change fragment on button click navigation drawer 
Java :: User input (scanner) 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =