Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java convert am pm to 24 hour

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
   public static void main(String [] args) throws Exception {
       SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
       SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a");
       Date date = parseFormat.parse("10:30 PM");
       System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date));
   }
}
Comment

java convert am pm to 24 hour

String result =                                       // Text representing the value of our date-time object.
    LocalTime.parse(                                  // Class representing a time-of-day value without a date and without a time zone.
        "03:30 PM" ,                                  // Your `String` input text.
        DateTimeFormatter.ofPattern(                  // Define a formatting pattern to match your input text.
            "hh:mm a" ,
            Locale.US                                 // `Locale` determines the human language and cultural norms used in localization. Needed here to translate the `AM` & `PM` value.
        )                                             // Returns a `DateTimeFormatter` object.
    )                                                 // Return a `LocalTime` object.
    .format( DateTimeFormatter.ofPattern("HH:mm") )   // Generate text in a specific format. Returns a `String` object.
;
Comment

PREVIOUS NEXT
Code Example
Java :: set text from strings.xml 
Java :: bufferedinputstream 
Java :: java php object 
Java :: quarkus maven skip test 
Java :: java sort arraylist of arraylist 
Java :: how to get request json web token in next js 
Java :: The this(Keyword) 
Java :: getsource java 
Java :: infinite for loop java example 
Java :: java string from byte array 
Java :: javafx get the controller of a pane 
Java :: check if a char is a space java 
Java :: list of string to string array in java 
Java :: get date from calendar java 
Java :: reversing the linked list 
Java :: javafx fxmlloader location is not set 
Java :: latest android sdk version 
Java :: add two variables in Java 
Java :: java lambda expressions 
Java :: objectmapper in java 8 
Java :: dropdown show hide div event in jsp 
Java :: java rgb to color 
Java :: combinations in java 
Java :: Design a class ‘Complex ‘with data members for real and imaginary part. Provide default and Parameterized constructors. Write a program to perform arithmetic operations of two complex numbers. 
Java :: android get device hieght 
Java :: call fragment method from activity 
Java :: ArrayList of prime numbers 
Java :: example of HashSet 
Java :: dont kill service in android studio 
Java :: how to call a non static method 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =