LocalDate - How to remove character 'T' in LocalDate

how to input date in java
java datetime format
datetimeformatter
how to remove from date in java
java 8 date
localdate format time
datetimeformatter remove z
how to convert string to localdate

How to remove T in my localDate?

I need to remove the 'T' to match data in my database.

This is my code

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.US);

String strLocalDate = patientDiagnosisByDoctor.getDiagnosisDateTime().toLocalDateTime().toString();

LocalDateTime localDate = LocalDateTime.parse(strLocalDate, formatter);

System.out.println(localDate);

I got this output:

2015-10-23T03:34:40

What is the best way to remove the 'T' character? Any idea guys?

What is the best way to remove the 'T' character? Any idea guys?

Use a DateTimeFormatter to format the value of LocalDateTime the way you want it...

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.US);

String strLocalDate = "2015-10-23T03:34:40";

LocalDateTime localDate = LocalDateTime.parse(strLocalDate, formatter);

System.out.println(localDate);
System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDate));
System.out.println(DateTimeFormatter.ofPattern("HH:mm:ss yyyy-MM-dd ").format(localDate));

Which prints...

2015-10-23T03:34:40
2015-10-23 03:34:40
03:34:40 2015-10-23 

Remember, date/time objects are just a container for amount of time which has passed since a fixed point in time (like the Unix epoch), they don't have a internal/configurable format of their own, they tend to use the current locale's format.

Instead, when you want to present the date/time value, you should first use a DateTimeFormatter to format the date/time value to what ever format you want and display that

I need to remove the 'T' to match data in my database.

Opps, missed that part.

In this case, you should be converting your Date/Time values to use java.sql.Timestamp and using a PreparedStatement to insert/update them

java - java - LocalDate, How to remove T in my localDate? I need to remove the 'T' to match data in my database. This is my code DateTimeFormatter formatter = DateTimeFormatter. LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed.

    String localTime = "2018-09-13 00:00:00";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
    LocalDateTime date = LocalDateTime.parse(localTime, formatter);
    String replace = date.toString().replace("T", " ");
    System.out.println(replace);

2018-09-13 00:00

Convert LocalDateTime to LocalDate, remove the time part, Java Data Type How to - Convert LocalDateTime to LocalDate, remove the time part. In this quick article, you'll learn how to convert a date string to an instance of LocalDate in Java 8 and higher. The new date and time API provides the parse() method for parsing a string to date. By default, this method accepts a date string in ISO-8601 format — ISO_LOCAL_DATE and parses it directly to an instance of LocalDate.

Simple option using the Joda-Time library.

new LocalDateTime(DateTimeZone.forID("Europe/London")).toString().replace("T", " ");

Java Date and Time, LocalDate, Represents a date (year, month, day (yyyy-MM-dd)) The following example will remove both the "T" and milliseconds from the date-time:  The following code shows how to create today, tomorrow and yesterday date. The code above generates the following result. The following code shows how to parse a string to LocalDate using Medium German format. The code above generates the following result. The following code shows how to get the date of the next pay day.

Official Gazette of the United States Patent and Trademark Office: , For example, users may add, remove, or change certain additional data blocks changes due to the removal of the character coded signature requirements of to be treated as being timely received on the local date at the location where  There is no method to replace or remove last character from string, but we can do it using string substring method. String str = "Hello World!"; String strNew = str.substring (0, str.length ()-1); //strNew is 'Hello World' Java String Remove Character and String Example. Here is the complete java class for the examples shown above.

Docs, Before parsing a RFC 2822 date time the string is cleansed to remove any comments and/or newline characters. The additional characters are legal in the format  A4 is the cell value that you want to remove characters; The number 2 means the number of characters you want to remove from the beginning of the text string. 2. Then, select the cell C4 and drag the fill handle down to the cells where you want to apply this formula, and all the first 2 characters have been removed from the text strings, see screenshot:

Using SQL String Functions to Clean Data, The TRIM function is used to remove characters from the beginning and end of a You can instruct your query to pull the local date and time at the time the  I would like a RegExp that will remove all special characters from a string. I am trying something like this but it doesn’t work in IE7, though it works in Firefox. A detailed description of the RegExp would be helpful as well. Or else put a trycatch block in the javascript code. – Kangkan Dec 7 '10 at 8:49.

Comments
  • Use a DateTimeFormat
  • "to match data in my database"? Are your dates stored as VARCHAR????
  • @Andreas I'm using datetime in MySQL
  • Well, then, unless you're building the SQL by string concatenation and leave yourself vulnerable to SQL Injection Attacks, the database will never see or return a value with a T in it, because you're sending/receiving Timestamp values in the JDBC calls, so your question is meaningless.
  • @Andreas exactly sir, Thanks a lot.
  • Any idea on how to remove trailing '.0' ? 2015-10-23 03:34:40.0 <---
  • substring(), but where are you getting that value? Nothing shown so far would do that.
  • from sql.timestamp, nevermind, MySQL does not detect that. Thank you sir
  • FYI: you'd normally change the format, but in your case, you don't need it, you jays need to use Timestamp and let the database worry about it
  • @Andreas Why not just change the format specifier, mind you, for inserting values in the database, you just need to use Timestamp and let the database worry about :P