Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-walker.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-walker.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/revision.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/revision.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/category.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/category.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/comment-template.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/comment-template.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/kses.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/kses.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/functions.wp-scripts.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/functions.wp-scripts.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/admin-bar.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/admin-bar.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-block-parser.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-block-parser.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1
How to Convert Date into Timestamp format in Java
Date and Time

How to Convert Date into Timestamp format in Java

Table of Contents

Program

import java.sql.Timestamp;
import java.time.Instant;

public class TimeStamp {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	  
	       Timestamp instant= Timestamp.from(Instant.now());  
	        System.out.println("1. from() method will return "+instant);  
	        
	        String str="2018-09-01 09:01:15";  
	        Timestamp timestamp= Timestamp.valueOf(str);  
	        System.out.println("2. value of Timestamp : "+timestamp);  
	       
	        Integer val=timestamp.getNanos();  
	        System.out.println("3. Fractional seconds component : "+val);  
	        Timestamp ts2 = Timestamp.valueOf("2018-09-01 09:01:16");  
	       
		System.out.println("4. Boolean value returned : "+timestamp.before(ts2));  
	}

}

Output

	1. from() method will return 2021-04-08 15:37:58.0525668
	2. value of Timestamp : 2018-09-01 09:01:15.0
	3. Fractional seconds component : 0
	4. Boolean value returned : true

Description

public BeanContext getPropagatedFrom()

Gets the BeanContext from which this event was propagated.

Returns:

the BeanContext from which this event was propagated

public static String valueOf​(int i)

Returns the string representation of the int argument.
The representation is exactly the one returned by the Integer.toString method of one argument.

Parameters:

i – an int.

Returns:

a string representation of the int argument.

See Also:

Integer.toString(int, int)

public int getNanos()

Gets this Timestamp object’s nanos value.

Returns:

this Timestamp object’s fractional seconds component

See Also:

setNanos(int)

public boolean before​(Date when)

Tests if this date is before the specified date.

Parameters:

when – a date.

Returns:

true if and only if the instant of time represented by this
Date object is strictly earlier than the instant represented by when; false otherwise.

Throws:

NullPointerException – if when is null