Last active
February 28, 2020 08:33
-
-
Save hendrasyp/6d5a7b92bbbf2fa1667cb7e8501113fb to your computer and use it in GitHub Desktop.
Formatting java.sql.Timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.AllArgsConstructor; | |
import lombok.Data; | |
import lombok.NoArgsConstructor; | |
import java.sql.Date; | |
import java.sql.Timestamp; | |
@AllArgsConstructor | |
@NoArgsConstructor | |
@Data | |
public class Foo { | |
public Timestamp EditDate; | |
public String StrEditDate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Date; | |
import java.sql.Timestamp; | |
import java.text.SimpleDateFormat; | |
public class MyClass { | |
public static void main(String args[]) { | |
// Jika dapat dari Database | |
// Foo foo = new Foo() | |
// Timestamp oStamp = foo.getEditDate(); | |
SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
// Timestamp timestamp = Timestamp.valueOf(oStamp.toString()); | |
Timestamp timestamp = Timestamp.valueOf("2020-02-25 05:52:56.000000"); | |
Long time = timestamp.getTime(); | |
Timestamp ts = new Timestamp(time); | |
String convertedDate = outputFormat.format(ts); | |
// foo.setStrEditDate(convertedDate); | |
System.out.println(timestamp); | |
System.out.println(time); | |
System.out.println(convertedDate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment