You are currently viewing Convert HTML input type datetime-local to Timestamp in Java

Convert HTML input type datetime-local to Timestamp in Java

Sharing is caring!

In this post, I’m going to show you how to convert HTML input type datetime-local to a timestamp in java.

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

//---------------------------------------

String valueFromHtml = "2022-03-11T09:01"
String dateTimeString = valueFromHtml.replace("T", " ");

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, formatter);
Timestamp examDateTime = Timestamp.valueOf(dateTime);

Keywords: html input datetime, html input type datetime, datetime local format, html datetime local, datetime local html, input type datetime local, input datetime HTML, date time input HTML, datetime local, datetime local, html date time input, datetime input HTML, html datetime input, timestamp html, input type date time, html timestamp, input datetime local, input type datetime, java localdatetime to timestamp.

Sharing is caring!

This Post Has One Comment

Leave a Reply