| |

VerySource

 Forgot password?
 Register
Search
View: 1092|Reply: 9

How to determine if the page input is legal time in java

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-13 14:30:02
| Show all posts |Read mode
How to determine if the time entered on the page is a legal time, referring to hours, minutes, and seconds (not dates)
   Example: 16:30:40
Reply

Use magic Report

1

Threads

15

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 United States

Post time: 2020-6-9 14:30:01
| Show all posts
It seems that this time does not include the date, this form is legal
If the landlord wants the hour to be between 0-24 and the minute to be between 0-60, it is not difficult to judge the string by yourself
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-9 16:00:01
| Show all posts
It seems not difficult!
The landlord is lazy!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-13 03:45:01
| Show all posts
Regular expression
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-13 13:15:01
| Show all posts
According to the format conversion, if there is no exception, the legal time is entered.

String str="16:30:40";
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
try{
Date d=sdf.parse(str);
}catch(Exception ex){
System.out.println("The input is incorrect!");
}
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-27 18:00:01
| Show all posts
Between 0-24 and between 0-60, just write a judgement
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-10 14:30:02
| Show all posts
Between 0-24 and between 0-60, just write a judgement

------------------------------------------------
Haha, this method is really silly
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-7-11 13:00:01
| Show all posts
Regular
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-14 01:00:01
| Show all posts
2. String conversion time, please note that you can not judge whether the time input is correct, whether the time input is correct, please use regular.
try
     {
      String st="2015-13-32 12:00";
     java.text.DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
              Date starttime = df.parse(st);
     System.out.println(starttime.toString());
     }
catch(Exception ex)
{

}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-7-23 11:30:02
| Show all posts
How to write this regular expression?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list