Java SimpleDateFormat – Formatting Dates

shape
shape
shape
shape
shape
shape
shape
shape

SimpleDateFormat is a Java class that allows you to format dates.

 

Converting dates in en-US (United States) format to pt-BR (Brazilian) format:

 

package com.masterdaweb.blog;

import java.text.ParseException;
import java.text.SimpleDateFormat;


public class Tutorial {


    public static void main(String[] args) throws ParseException {
        String usDate = "1992-08-25 13:30";
        
        SimpleDateFormat brFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
        SimpleDateFormat usFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        
        String FormattedDate = brFormat.format(usFormat.parse(usDate));
        
        System.out.println(FormattedDate); // Saída: 25-08-1992 13:30
    }
    
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.