-3

I want to get the current time and date of the device on my android app, but without any punctuation marks.

I mean like:
05112016
and
1946

How can I do that on my android app?

EDIT 1#: The question isn't a duplicate, since the answer in the suggested duplicate isn't what I'm asking. When I run the code from the answer and delete any punctuation marks I get "Nov52016101232" instead of what I want which is "05112016101232".

halfer
  • 19,824
  • 17
  • 99
  • 186
Ido Naveh
  • 2,442
  • 3
  • 26
  • 57
  • 1
    Possible duplicate of [How to format date string in java?](http://stackoverflow.com/questions/11046053/how-to-format-date-string-in-java) – Andreas Nov 05 '16 at 17:49
  • @Andreas It's not a duplicate since it's not what I want. I want to get a clear string without anything. Not slashes, not dots, not dashes and not anything else. Just numbers. – Ido Naveh Nov 05 '16 at 17:54
  • Yes, so you give a format string requesting that! You're still just asking how for format the date as a string, aren't you? – Andreas Nov 05 '16 at 17:55
  • 1
    Can't you can use replaceAll method to remove the punctuation marks? – Nongthonbam Tonthoi Nov 05 '16 at 17:58

1 Answers1

2

Use SimpleDateFormat to achieve this.

//date
 SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy", Locale.ENGLISH);
 sdf.format(new Date());

 //time 
 SimpleDateFormat sdf = new SimpleDateFormat("HHmm", Locale.ENGLISH);
 sdf.format(new Date());
Ravi Theja
  • 3,371
  • 1
  • 22
  • 34