"T" در مثال بالا برای جدا کردن تاریخ از زمان استفاده می شود. می توانید از کلاس DateTimeFormatter استفاده کنید
با روش ofPatte در همان بسته برای قالب بندی یا تجزیه اشیاء تاریخ-زمان.
()
مثال زیر هم "T" و هم میلی ثانیه را از تاریخ-زمان حذف می کند:
import java.time.LocalDateTime; // Import the LocalDateTime class
import java.time.format.DateTimeFormatter; // Import the DateTimeFormatter class
public class MyClass {
public static void main(String[] args) {
LocalDateTime myDateObj = LocalDateTime.now();
System.out.println("Before formatting: " + myDateObj);
DateTimeFormatter myFormatObj = DateTimeFormatter.ofPatte
("dd-MM-yyyy HH:mm:ss");
String formattedDate = myDateObj.format(myFormatObj);
System.out.println("After formatting: " + formattedDate);
}
}
The output will be:
متد ofPatte همه انواع مقادیر را میپذیرد، اگر میخواهید نمایش دهید
()
تاریخ و زمان در قالبی متفاوت به عنوان مثال:
| مقدار | مثال | امتحان کنید |
|---|---|---|
| yyyy-MM-dd | "29-09-1988" | امتحان کنید» |
| dd/MM/yyyy | "29/09/1988" | امتحان کنید» |
| dd-MMM-yyyy | "29-سپتامبر 1988" | امتحان کنید» |
| E، MMM dd yyyy | "پنجشنبه، 29 سپتامبر 1988" | امتحان کنید» |