This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.
I want the current timestamp to look like this: 1320917972
int time = (int) (System.currentTimeMillis());
Timestamp tsTemp = new Timestamp(time);
String ts = tsTemp.toString();
Copy the code
Answer:
You can use the following code, on which I successfully ran:
/ * * * *@return yyyy-MM-dd HH:mm:ss formate date as string
*/
public static String getCurrentTimeStamp(a){
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentDateTime = dateFormat.format(new Date()); // Find todays date
return currentDateTime;
} catch (Exception e) {
e.printStackTrace();
return null; }}Copy the code
Answer 2:
Here’s an easy to understand timestamp to use with a filename in case someone needs the same thing I do:
package com.example.xyz;
import android.text.format.Time;
/** * Clock utility. */
public class Clock {
/**
* Get current time in human-readable form.
* @return current time as a string.
*/
public static String getNow(a) {
Time now = new Time();
now.setToNow();
String sTime = now.format("%Y_%m_%d %T");
return sTime;
}
/** * Get current time in human-readable form without spaces and special characters. * The returned value may be used to compose a file name. *@return current time as a string.
*/
public static String getTimeStamp(a) {
Time now = new Time();
now.setToNow();
String sTime = now.format("%Y_%m_%d_%H_%M_%S");
returnsTime; }}Copy the code
Q: How does Spring use multiple @requestMapping annotations?
Is it possible for @requestMapping to use multiple annotations on a method?
Such as
@RequestMapping("/")
@RequestMapping("")
@RequestMapping("/welcome")
public String welcomeHandler(a){
return "welcome";
}
Copy the code
Answer 1:
@RequestMapping has a String[] value parameter, so you should be able to specify multiple values, as follows:
@RequestMapping(value={“”, “/”, “welcome”})
About this code,. There was some controversy, and someone was having trouble getting the “” or”/” values to actually work in my application.
Answer 2:
According to my test, @ RequestMapping (value = {” “, “/”}) – only “/”, “” is invalid. But I found it works: @requestMapping (value={“/”, “* “}) can” * “match anything, so if nothing else it will be the default handler.
Answer 3:
If you still want to get the uri being called, it is best to use the PathVariable annotation.
@PostMapping("/pub/{action:a|b|c}")
public JSONObject handlexxx(@PathVariable String action, @RequestBody String reqStr){... }Copy the code