I wanted to convert date in yymmdd format to YYYYMMDD, but when using the simpledateformat class i am getting the years after 1970, but the requirement is of the year which is prior to 1970.
is there any way to convert the date in java prior to 1970?
786 Views Asked by Shubham At
1
There are 1 best solutions below
Related Questions in JAVA
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in JAVA-8
- Java control panel glitching or becomes yellowish
- Uneven Load Distribution in Kubernetes Pods with Multithreaded Execution using fork join pool
- test result: Error. Program `sh' timed out (timeout set to 480000ms, elapsed time including timeout handling was 480002ms)
- java.net.ConnectException: Connection timed out: no further information Java to SOAP
- Java Stream, Need to update list of list objects
- Setting up different Java class fields value by a single value on some counter value
- feign client Spring boot
- `TYPE_USE` vs `TYPE` vs `TYPE_PARAMETER` annotations
- Error faced in trying to install Java 8 on Raspberry Pi 4B
- Grouping by multiple fields and counting using in Java 8
- How to customize mention notifications in liferay 7.3.5
- Without _JAVA_OPTIONS and JAVA_TOOL_OPTIONS, whether LeanFT will work or not?
- How to build a CriteriaQuery from SQL query
- From a string I am manually setting the date and time in calendar, for the other days it is working fine but for 28 and 29 Feb it is setting wrong val
- Sort strings containing numbers, chars and ponctuations in ”human readable order”
Related Questions in SIMPLEDATEFORMAT
- SimpleDateFormat gives a wrong date when input a wrong format date string
- Execute Date arithmetic without daylight saving adjustment
- I got the error "java.text.ParseException: Unparseable date: "1/10/24 7:00 PM"" when trying to parse
- Parse string date to millis in kotlin
- How to convert a string with extra characters
- Unparseable date Exception on Unit Testing via Mockito
- Why is Java epoch time off by 30 minutes when parsing via SimpleDateFormat
- Calendar Class method in Java seems to be not giving correct result
- Date Pattern starting from 12 hours
- How to convert Date from 2023-11-10 09:44:00.038860 to 2023-11-10T09:44:20.001+00:00 in spring boot application
- Simple Date format not recognised
- Date Parse Exception in Android for input Mon, 11 Sep 2023 15:49:32 GMT
- SimpleDateFormat string parsing issue in a Specific Android Device
- Converting Server GMT date and time to User specified date and time zone with specified format, returning with Date datatype
- SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); customize the timezone
Related Questions in DATE-FORMATTING
- How do you combine strings and string variables in python
- add time (char(8)) to date column
- PHP Fatal error: Call to a member function format() on boolean
- date time to date (Y/m/d)
- How to avoid seconds in datetimepicker?
- Formatting dates in PostgreSQL
- sql query date formatting (Hours:Minutes)
- How to serialize a custom formatted time to/from xml in Go?
- use set language in a sql function
- Python: strptime() formatting
- Converting Date in M d, Y format leads to display date in other rows
- Choosing the wanted part of a date
- Excel/ How to convert number of date to
- Force localization of the allowedUnits in DateComponentsFormatter
- Formatting datetime in pandas columns as Quarters
Related Questions in 2-DIGIT-YEAR
- Leap year and symbol used
- Create new sheet with google Apps Script and set name as 21-08
- Why Year part of date in update query statement updating wrong year when year is >= 2050
- Convert date format: 2 digit year to 4 digit year
- JSON.NET: String '7/1/20 14:15' was not recognized as a valid DateTime
- Number date to Alphabetic in awk
- Error converting date with two digits for the Year field
- Date conversion from "JAN02/19 to 2019-01-02
- how to get year and week from date
- is there any way to convert the date in java prior to 1970?
- Assigning a year value to sbyte
- Character 2 digit year conversion to year only
- How to convert "yyyyMMdd" date format into "ccyyMMdd" simpledateformat in java
- How to convert two digit year to full year using Java 8 time API
- how to use str_to_date (MySQL) to parse two-digit year correctly
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
java.time
Parsing input
The way to control the interpretation of the 2-digit year in
yymmddis through theappendValueReducedmethod ofDateTimeFormatterBuilder.Supplying a base year of 1870 causes two-digit years to be interpreted in the range 1870 through 1969 (so always prior to 1970). Supply a different base year according to your requirements. Also unless you are sure that input years all across a period of 100 years are expected and valid, I recommend you do a range check of the parsed date.
Formatting and printing output
Output in this example is:
If instead input was
700114, output is:Use LocalDate for keeping your date
Instead of converting your date from one string format to another, I suggest that it’s better to keep your date in a
LocalDate, not a string (just like you don’t keep an integer value in a string). When your program accepts string input, parse into aLocalDateat once. Only when it needs to give string output, format theLocalDateback into a string. For this reason I have also separated parsing from formatting above.Link
Oracle tutorial: Date Time explaining how to use java.time.