-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsingException.java
More file actions
26 lines (24 loc) · 987 Bytes
/
ParsingException.java
File metadata and controls
26 lines (24 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.company;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class ParsingException {
static void convertDateFormat(String inputDate) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
Date date = sdf.parse(inputDate);
SimpleDateFormat outsdf = new SimpleDateFormat("yyyy-MM-dd");
String outputDate = outsdf.format(date);
System.out.println("After changing date format to yyyy/MM/dd : " + outputDate);
}catch (ParseException e) {
System.out.println("Some errors in converting date formats. Exception");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the date in dd/MM/yyyy format : ");
String inputDate = sc.nextLine();
convertDateFormat(inputDate);
}
}