Sunday, March 10, 2019

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

public class MethodName {

String methodName;

public static String getName() {

return new Object() {
}.getClass().getEnclosingMethod().getName();

}

public static String dateStamp() {

return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());

}

public static void main(String[] args) {

System.out.println(dateStamp());
System.out.println(getName());

System.out.println(new Object() {
}.getClass().getEnclosingMethod().getName());
}

}

No comments:

Post a Comment