Last active
October 28, 2022 15:37
-
-
Save patmcclellan/1f91f138fed89a70142864d84d360ff8 to your computer and use it in GitHub Desktop.
RAD2 Demo: Datetime functions (static vs non-static)
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
/** | |
* Let's look at the method signature for newInstance() | |
* public static Datetime newInstance(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second) | |
* | |
* it says right there that it's a static method, so we invoke it by using the Class name | |
* | |
*/ | |
Datetime appointment = Datetime.newInstance(2022,10,29,11,15,0); | |
Datetime nextWeekAppt = appointment.addDays(7); | |
// Is addDays() static or non-static? | |
System.debug('🧿 appointment tomorrow: ' + appointment.format('EEE, MMM d yyyy HH:mm a')); | |
System.debug('🍊 next Saturday: ' + nextWeekAppt.format('EEE, MMM d yyyy HH:mm a')); | |
/** | |
* The parameters for the format() method follow Javascript patterns: | |
* https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html | |
* | |
* The method signature for format() is | |
* public String format(String dateFormatString) | |
* note there's not 'static' mentioned, so it's a non-static | |
* method on the instance | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment