what is the Java equivalent of sscanf for parsing values from a string using a known pattern?

后端 未结 8 806
梦如初夏
梦如初夏 2020-11-27 06:01

So I come from a C background (originally originally, though I haven\'t used that language for almost 5 years) and I\'m trying to parse some values from a string in Java. In

相关标签:
8条回答
  • 2020-11-27 06:59

    For "17-MAR-11 15.52.25.000000000":

    SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yy HH.mm.ss.SSS");
    
    try 
    {
        Date parsed = format.parse(dateString);
        System.out.println(parsed.toString());
    }
    catch (ParseException pe)
    {
        System.out.println("ERROR: Cannot parse \"" + dateString + "\"");
    }
    
    0 讨论(0)
  • 2020-11-27 06:59

    System.in.read() is another option.

    0 讨论(0)
提交回复
热议问题