How do i convert inputted DATE into a different format

Hello, I was wondering if someone can help. I need to verify a user inputted Date that’s in specific format, but then outputted in a different format. For example if user inputs the date as 12/09/2019 in a admin section, which is in the format of (‘MM/dd/yyyy’), but then it’s outputted as (‘Saturday, December 12, 2019’) , which is (‘EEEE, MMMM dd, yyyy’).

How do I convert the inputted date into a new format and verify that it is displayed in (‘EEEE, MMMM dd, yyyy’). Any example would be extremely helpful.

hi,

try this one

SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, yyyy",Locale.ENGLISH);
Date parsedDate = null;
String sentDate = "Saturday, December 12, 2019";
parsedDate = sdf.parse(sentDate);
SimpleDateFormat print = new SimpleDateFormat("MM/dd/yyyy");
String sDate = print.format(parsedDate);

output
12/12/2019

1 Like

@Timo_Kuisma

I actually needed it the other way around (MM/dd/yyyy) > (EEEE, MMMM dd, yyyy), but what you provided was more than enough for me to get to where I needed. Thanks appreciate the help. Added my results below in case anyone needs for reference.

import com.kms.katalon.core.logging.KeywordLogger as KeywordLogger

KeywordLogger log = new KeywordLogger()
SimpleDateFormat sdf = new SimpleDateFormat(“MM/dd/yyyy”);
Date parsedDate = null;
String sentDate = “12/09/2019”;
parsedDate = sdf.parse(sentDate);
SimpleDateFormat print = new SimpleDateFormat(“EEEE, MMMM dd, yyyy”,Locale.ENGLISH);
String sDate = print.format(parsedDate);
log.logInfo(sDate)

output: Monday, December 09, 2019

hi,

good to know that this helped you :sunglasses:

I am trying to use this, but getting an error “unable to resolve class SimpleDateFormat” What reference do I need to import to be able to use this? TIA

hello,

check this page
https://alvinalexander.com/java/simpledateformat-convert-date-to-string-formatted-parse

Thanks @Timo_Kuisma1

So I tried this, but my output is not the correct date
SimpleDateFormat sdf = new SimpleDateFormat(“MM/DD/YYYY”)
Date parsedDate = null
String sentDate = “9/1/20”
parsedDate = sdf.parse(sentDate);
println (parsedDate)
SimpleDateFormat print = new SimpleDateFormat(“MM/DD/YYYY”)
String sDate = print.format(parsedDate)
println (sDate)

Output is 12/365/0020

hi,

and your output should be?

Output should be 09/01/2020.

I think to use this function I need to send in the correct format of the date and it will then reformat to any other way we need…I sent in date “9/1/20” and wanted it be reformatted to “09/01/2020”

hello,

you were very close
SimpleDateFormat sdf = new SimpleDateFormat('dd/mm/yy')
Date parsedDate = null
String sentDate = '9/1/20'
parsedDate = sdf.parse(sentDate);
println (parsedDate)
sdf = new SimpleDateFormat('dd/mm/YYYY')
String sDate = sdf.format(parsedDate)
println (sDate)

//Thu Jan 09 00:01:00 EET 2020
//09/01/2020
1 Like

@Timo_Kuisma1 aah… see my syntax mistake for the year 4 digit year. It should have been 2 digit. the very first line… thanks for catching that!! it works now for me.

Hi, i am retrieving the date from CSV file and sending it into web application,Here both the format’s are different how do i convert the CSV date format into application format.
CSV date format “01/06/2020”
Web Application format “01062020”

@bhargavia You can try the String function, replace("/", “”).

You may also try convert the CSV (date format) string value to a date and then setText the new “date” into the Web Application.

Thank You.