English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

String b=date.toString();
String a=b.substring(3,5);

Not giving desired o/p

2007-03-21 22:38:30 · 5 answers · asked by ritu s 1 in Computers & Internet Programming & Design

5 answers

check the API of substring carefully
it gives a substring from 3rd position to 8th position

2007-03-21 22:43:18 · answer #1 · answered by Anonymous · 0 1

1.public String substring(int beginIndex)

Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.

Examples:

"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)


Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.

2.public String substring(int beginIndex,
int endIndex)

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Examples:

"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"


Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

2007-03-26 02:11:17 · answer #2 · answered by srihari_reddy_s 6 · 0 0

b.substring(x,y)
x is the starting position in the string b (start counting from 0)
y is the length of the substring result

2007-03-22 05:43:02 · answer #3 · answered by abd 5 · 0 1

First of all you need to tell us your desired output...

Take note the format of Date String
DDD MMM DD HH:MM:SS GMT+HH:MM YYYY

So if you want to take the time only
String a = b.substring(11, 20);

if you want the date MMM DD YYYY
String a = b.substring( 3, 9) + ", " + b.substring( 30, 34 );

/* GoOd LuCk */

2007-03-26 02:28:21 · answer #4 · answered by Liviawarty J 2 · 0 0

hey visiy http://myjava.batcave.net

2007-03-22 10:06:13 · answer #5 · answered by Eranga D 2 · 0 0

fedest.com, questions and answers