SimpleDateFormat to format second value
In this chapter you will learn:
Formatting seconds using SimpleDateFormat
We can see from the output that the s
and ss
would show the same value.
import java.text.SimpleDateFormat;
import java.util.Date;
// j a va 2 s. c om
public class Main {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("s");
System.out.println("seconds in s format : " + sdf.format(date));
sdf = new SimpleDateFormat("ss");
System.out.println("seconds in ss format : " + sdf.format(date));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Date, Time