Created
April 5, 2020 16:26
-
-
Save ilhamarrouf/df963a80dda7b4c43b1da3416d1d0cb4 to your computer and use it in GitHub Desktop.
Business Application Design TK 2
This file contains hidden or 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.util.Calendar; | |
import java.util.Formatter; | |
import java.util.Locale; | |
import java.text.SimpleDateFormat; | |
public class DateFormaterPlayGround | |
{ | |
String locale = "id"; | |
public static void main(String[] args) | |
{ | |
DateFormaterPlayGround formater = new DateFormaterPlayGround(); | |
System.out.println("Format date asli = "+formater.getWithFormat()); | |
System.out.println("======================================================="); | |
System.out.println("dd/MM/yy ---> "+formater.getWithFormat("dd/MM/yy")); | |
System.out.println("dd MMMM yyyy ---> "+formater.getWithFormat("dd MMMM yyyy")); | |
System.out.println("EEEE, dd MMMM, \"yy ---> "+formater.getWithFormat("EEEE, dd MMMM, \"yy")); | |
System.out.println("h:mm a ---> "+formater.getWithFormat("h:mm a")); | |
System.out.println("H:mm ---> "+formater.getWithFormat("H:mm")); | |
System.out.println("H:mm:ss:SSS ---> "+formater.getWithFormat("H:mm:ss:SSS")); | |
System.out.println("yyyy.MM.dd G at hh:mm:ss z ---> "+formater.getWithFormat("yyyy.MM.dd G")+" at "+formater.getWithFormat("hh:mm:ss z")); | |
System.out.println("yyyy.MMMMM.dd GGG hh:mm aaa ---> "+formater.getWithFormat("yyyy.MMMMM.dd GGG hh:mm aaa")); | |
System.out.println("dd MMMM yyyy, Pukul HH:mm:ss:SSSSS ---> "+formater.getWithFormat("dd MMMM yyyy")+", Pukul "+formater.getWithFormat("HH:mm:ss:SSSSS")); | |
formater.setLocal("fr"); | |
System.out.println("EEEE, dd MMMM, yyyy ---> "+formater.getWithFormat("EEEE, dd MMMM, yyyy")); | |
System.out.println("Dalam format timestamp = "+System.nanoTime()); | |
} | |
public String getWithFormat(String... format) | |
{ | |
Calendar calendar = Calendar.getInstance(); | |
if (format.length > 0) { | |
SimpleDateFormat formater = new SimpleDateFormat(format[0], new Locale(this.locale)); | |
return formater.format(calendar.getTime()).toString(); | |
} else { | |
return calendar.getTime().toString(); | |
} | |
} | |
public void setLocal(String local) | |
{ | |
this.locale = local; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment