0

I'm using beanshell and I need to convert a string in the format '2012.08.14 07:30:00.000' to date time integer in the format 1344925800000

Does anyone have any ideas?

Thanks in advance

Al

1 Answers1

0

I hope that your example result is only an example, because using Java means I obtain a different result. But a standard is to use the number of milliseconds since January 1, 1970, 00:00:00 GMT.

I don't know if there is a more generic way, that would allow you to specify a format string. Here I use a string conversion and a format for specific locale.

import java.text.DateFormat;

sDate = "2012.08.14 07:30:00.000";
// replace beginning dots with hyphens
sDate = sDate.replaceFirst("([0-9]{4})\\.([0-9]{2})\\.([0-9]{2}) ", "$1-$2-$3 ");
// use a date format from a specified locale
formatter = DateFormat.getDateInstance(
    DateFormat.MEDIUM,
    new Locale("PL"));
javax.swing.JOptionPane.showMessageDialog(null,
    "time=" + formatter.parse(sDate).getTime());
Jarekczek
  • 7,456
  • 3
  • 46
  • 66