Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How to convert timestamp to time in java

//Timestamp to HH:mm:ss format
Long Timestamp = 1633304782;
Date timeD = new Date(Timestamp * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

String Time = sdf.format(timeD);

//RESULT this code convert 1633304782 to 05:46:33
Comment

Java String to Timestamp

import java.sql.Timestamp;

public class StringToTimeStamp {
    public static void main(String[] args) {

        String dateTime = "2020-12-12 01:24:23";

        Timestamp timestamp = Timestamp.valueOf(dateTime);
        System.out.println(timestamp);
    }
}
Comment

timestamp to date java

String timestampToDate(long timestamp, String pattern)
    {
        Date timeD = new Date(timestamp);
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(timeD);
    }

//You can use this for both date or time.
// long timestamp = System.currentTimeMillis();
// eg: for date use it like this:
//timestampToDate(timestamp, "dd MMM, yyyy");
// eg: for time use it like this:
//timestampToDate(timestamp, "hh:mm a");
// eg: for both:
//timestampToDate(timestamp, "dd MMM, yyyy - hh:mm a");
Comment

date to timestamp java

All you need to do is change the string within the java.text.SimpleDateFormat constructor to: "MM-dd-yyyy HH:mm:ss".

Just use the appropriate letters to build the above string to match your input date.
Comment

PREVIOUS NEXT
Code Example
Java :: how to remove duplicate elements from char array in java 
Java :: Java Create a ConcurrentHashMap 
Java :: How to connect from Android emulator to application on localhost? 
Java :: java big integer to int 
Java :: how to make java list 
Java :: java remove last character 
Java :: iterate through hashMap by forEach loop 
Java :: how to check the end of a string java 
Java :: get raondom from array java 
Java :: for loop javasctip 
Java :: joining an array of strings in java 
Java :: android separator line in view 
Java :: set path in windows 
Java :: List into string java 
Java :: java create unmodifiable list 
Java :: template competitive programming java 
Java :: java get file name without extension 
Java :: how to check base64 in java 
Java :: java initialize string array 
Java :: java array add element 
Java :: java files 
Java :: how to change actionbar color in android programmatically 
Java :: java protected private public 
Java :: java variables 
Java :: insert string in string java 
Java :: how to round double to 2 decimal places java 
Java :: java random double between 0 and 1 
Java :: java find if element of list in present in another list 
Java :: Java program to print decimal to octal conversion 
Java :: press enter in robot java 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =