天天看點

js_日期格式解析

  1. Current month of the year format mm

    CURRENT_MONTH_YEAR

Date now = new Date();
int month = now.getMonth() + 1;
String monthStr = month.toString();
if (month < 10) monthStr = '0' + monthStr;
returnValue(monthStr);
           
  1. Current year format yyyy
Date now = new Date();
int year = now.getYear() + 1900;
String yearStr = year.toString();
returnValue(yearStr);
           
  1. Current month format mm/yyyy
Date now = new Date();
int month = now.getMonth() + 1;
String monthStr = month.toString();
if (month < 10) monthStr = '0' + monthStr;
int year = now.getYear() + 1900;
String toReturn = monthStr + '/' + year.toString();
returnValue(toReturn);
           
  1. Current date format dd/mm/yyyy
Date now = new Date();
int day = now.getDate();
String dayStr = day.toString();
if (day < 10) dayStr = '0' + dayStr;
int month = now.getMonth() + 1;
String monthStr = month.toString();
if (month < 10) monthStr = '0' + monthStr;
int year = now.getYear() + 1900;
String toReturn = dayStr + '/' + monthStr + '/' + year.toString();
returnValue(toReturn);
           

繼續閱讀