When developing user interfaces for management software you usually need to check what the user inputs in order to store the values in a database or a file. Java offers different alternatives to parse a String (normally the way user inputs values to the system) to other data types.

The class SimpleDateFormat from the package java.text offers a simple method to do this. You just have to call parse(String youDate) in order to get a java.util.Date.

Following you can find some code which explains this method and some of its particularities:

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

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

<span style="color: #3f7f59;">/* We create the SimpleDateFormat object with the desired pattern */</span>

SimpleDateFormat sdf=newSimpleDateFormat("dd/MM/yyyy");

<span style="color: #3f7f59;">/* This is very important. If you need strict parsing, (i.e. January</span>

<span style="color: #3f7f59;"> * will only have 31 days you must set this to false.</span>

<span style="color: #3f7f59;"> * If you don't do this when you parse "32/01/2007" the date you'll</span>