Luke Batley
Luke Batley

Reputation: 2402

limiting the length of a string

I have a string that says 15:00:00 how can I limit the length of the string so it says 15:00 ?

Upvotes: 0

Views: 172

Answers (3)

paulgavrikov
paulgavrikov

Reputation: 1891

For dates

Date date = new Date();
SimpleDateFormat sd = new SimpleDateFormat("HH:mm");
sd.format(date); //will return formatted date

Upvotes: 3

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

try this:

String time = "15:00:00";
String str =time.substring(0,result.length() - 3);

Upvotes: 0

user370305
user370305

Reputation: 109257

Try this,

String time = "15:00:00";
time = time.subString(0,time.lastIndexOf(":"));

Upvotes: 3

Related Questions