-2

How can I convert this format of date in Java?

DateTime.Now.AddDays(-5).ToString ("u").Replace ('Z', ' ') , 

Here is an example how it is

"<FechaDesde>"+DateTime.Now.AddDays(-5).ToString ("u").Replace ('Z', ' ')+"</FechaDesde>" +
2
  • "Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question."
    – user253751
    Jan 12, 2015 at 5:06
  • I updated my question, please review it above please!
    – Jose Perez
    Jan 12, 2015 at 5:07

1 Answer 1

1
// new Calendar represents current time
Calendar cal = Calendar.getInstance();

// subtract five days
cal.add(Calendar.DATE, -5);

// specify format required
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS); // or whatever format you want

// format the date and add the prefix and suffix
String formattedDate = "<FechaDesde>" + sdf.format(cal.getTime()) + "</FechaDesde>";

Not the answer you're looking for? Browse other questions tagged or ask your own question.