Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (3.9k points)

I just created sample BB app, which can allow to choose the date.

DateField curDateFld = new DateField("Choose Date: ",

  System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT);

After choosing the date, I need to convert that long value to String, so that I can easily store the date value somewhere in database. I am new to Java and Blackberry development.

long date = curDateFld.getDate();

How should I convert this long value to String? Also I want to convert back to long from String. I think for that I can use long l = Long.parseLong("myStr");?

1 Answer

0 votes
by (46k points)

Check out the reference documentation for the String class: String s = String.valueOf(date);

If your Long sway be null and you don't require to receive a 4-letter "null" string, you sway use Objects.toString, like: String s = Objects.toString(date, null);

You change it applying Long l = Long.valueOf(s); but in that way, you require to get NumberFormatException

Related questions

0 votes
1 answer
asked Sep 23, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...