本文整理汇总了Java中java.time.LocalDate.getDayOfMonth方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.getDayOfMonth方法的具体用法?Java LocalDate.getDayOfMonth怎么用?Java LocalDate.getDayOfMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.getDayOfMonth方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.time.LocalDate; //导入方法依赖的package包/类
public static void main(String[] args) {
/* Read and save input as LocalDates */
Scanner scan = new Scanner(System.in);
LocalDate returnDate = readDate(scan);
LocalDate expectDate = readDate(scan);
scan.close();
/* Calculate fine */
int fine;
if (returnDate.isEqual(expectDate) || returnDate.isBefore(expectDate)) {
fine = 0;
} else if (returnDate.getMonth() == expectDate.getMonth() && returnDate.getYear() == expectDate.getYear()) {
fine = 15 * (returnDate.getDayOfMonth() - expectDate.getDayOfMonth());
} else if (returnDate.getYear() == expectDate.getYear()) {
fine = 500 * (returnDate.getMonthValue() - expectDate.getMonthValue());
} else {
fine = 10000;
}
System.out.println(fine);
}
示例2: showPerson
import java.time.LocalDate; //导入方法依赖的package包/类
@FXML
public void showPerson(Person person) {
if (person == null) {
firstNameLabel.setText("");
lastNameLabel.setText("");
cityLabel.setText("");
birthdateLabel.setText("");
} else {
firstNameLabel.setText(person.getFirstName().getValue());
lastNameLabel.setText(person.getLastName().getValue());
cityLabel.setText(person.getLastName().getValue());
LocalDate date = (LocalDate)person.getBithdate().getValue();
String strDate = date.getDayOfMonth() +"."+date.getMonthValue()+"."+date.getYear();
birthdateLabel.setText(strDate);
}
}
示例3: next
import java.time.LocalDate; //导入方法依赖的package包/类
private LocalDate next(LocalDate date) {
int newDayOfMonth = date.getDayOfMonth() + 1;
if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) {
return date.withDayOfMonth(newDayOfMonth);
}
date = date.withDayOfMonth(1);
if (date.getMonth() == Month.DECEMBER) {
date = date.withYear(date.getYear() + 1);
}
return date.with(date.getMonth().plus(1));
}
示例4: test_date_print
import java.time.LocalDate; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
String formatted = f.format(date);
assertEquals(formatted, text);
}
示例5: GetLocalDate
import java.time.LocalDate; //导入方法依赖的package包/类
private static DateObjects GetLocalDate() {
final Date date = new Date();
final LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
final int year = localDate.getYear();
final int month = localDate.getMonthValue();
final int day = localDate.getDayOfMonth();
return new DateObjects(year, month, day);
}
示例6: login
import java.time.LocalDate; //导入方法依赖的package包/类
public static Clients login(String email, String password) {
if (email != null && password != null && !email.isEmpty() && !password.isEmpty()) {
EntityManager em = EMFUtil.getEMFactory().createEntityManager();
String query = "SELECT c FROM Clients c WHERE c.email = :email and c.approved = 'Yes'";
TypedQuery<Clients> qClient = em.createQuery(query, Clients.class);
try {
qClient.setParameter("email", email.toLowerCase());
Clients client = qClient.getSingleResult();
if (client != null && CustomUtilities.hashPassword(password, CustomUtilities.hexToBytes(client.getSalt()))[0].equals(client.getPassword())) {
//Sets monthly profiles viewed to 0 if beginning of the month
LocalDate dateToday = LocalDate.now();
if (dateToday.getDayOfMonth() == 1) {
client.setProfilesViewedThisMonth(0);
if (client.getCompany() != null) {
client.getCompany().setProfilesViewedThisMonth(0);
}
client = ClientPersistence.merge(client);
}
ClientLoginLogs loginLog = ClientPersistence.addLoginLog(client);
client.getLoginLog().add(loginLog);
return client;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
em.close();
}
}
return null;
}
示例7: test_date_parse
import java.time.LocalDate; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
TemporalAccessor parsed = f.parse(text, pos);
assertEquals(pos.getIndex(), text.length());
assertEquals(pos.getErrorIndex(), -1);
assertEquals(LocalDate.from(parsed), date);
}
示例8: getOriginDefaultValueNonNull
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* get origin default value in string
* @param value a date represents in string in "yyyy-MM-dd" format
* @return a {@link Date} Object
*/
@Override
public Object getOriginDefaultValueNonNull(String value) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(value, dateTimeFormatter);
return new Date(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
}
示例9: previous
import java.time.LocalDate; //导入方法依赖的package包/类
private LocalDate previous(LocalDate date) {
int newDayOfMonth = date.getDayOfMonth() - 1;
if (newDayOfMonth > 0) {
return date.withDayOfMonth(newDayOfMonth);
}
date = date.with(date.getMonth().minus(1));
if (date.getMonth() == Month.DECEMBER) {
date = date.withYear(date.getYear() - 1);
}
return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
示例10: fileMethod
import java.time.LocalDate; //导入方法依赖的package包/类
public static void fileMethod(File file) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String jsonString = "";
String tempString;
while ((tempString = bufferedReader.readLine()) != null) {
jsonString += tempString;
}
bufferedReader.close();
jsonString = Unicode2utf8Utils.convert(jsonString).replaceAll("<.*?>", "");
Map map = JSON.parseObject(jsonString);
if (map.get("created_at") == null) {
if (map.get("date") == null){
System.out.println(cnt++ + " error files.");
file.delete();
}
return;
}
String created_at = (String) map.get("created_at");
String date;
Pattern patternA = Pattern.compile("\\d+-\\d+-\\d+");
Pattern patternB = Pattern.compile("\\d+-\\d+");
Pattern patternC = Pattern.compile("\\d{1,2}:\\d{1,2}");
if (patternA.matcher(created_at).find()) {
date = created_at.substring(0, 10);
} else if (patternB.matcher(created_at).find()) {
date = "2017-" + created_at.substring(0, 5);
} else if (patternC.matcher(created_at).find()) {
LocalDate localDate = LocalDate.now();
date = localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.getDayOfMonth();
} else {
file.delete();
System.out.println(cnt++ + " error files.");
return;
}
map.put("date", date);
map.remove("created_at");
map.remove("thumbnail_pic");
map.remove("bmiddle_pic");
map.remove("original_pic");
map.remove("itemid");
map.remove("status");
map.remove("rid");
map.remove("cardid");
map.remove("visible");
if (map.get("pics") != null) {
List list = (List) map.get("pics");
map.put("pics", list.size());
} else {
map.put("pics", 0);
}
if (map.get("user") != null) {
Map userMap = (Map) map.get("user");
userMap.remove("profile_image_url");
userMap.remove("cover_image_phone");
userMap.remove("profile_url");
userMap.remove("description");
userMap.remove("follow_me");
userMap.remove("following");
}
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)));
printWriter.print(com.alibaba.fastjson.JSON.toJSONString(map));
printWriter.close();
} catch (Exception e) {
file.delete();
System.out.println(cnt++ + " error files.");
// e.printStackTrace();
}
}
示例11: localDateToLong
import java.time.LocalDate; //导入方法依赖的package包/类
private Long localDateToLong(LocalDate localDate)
{
return localDate.getYear() * 10000L + localDate.getMonth().getValue() * 100L + localDate.getDayOfMonth();
}
示例12: localDateToDateValue
import java.time.LocalDate; //导入方法依赖的package包/类
static DateValue localDateToDateValue(LocalDate date) {
return new DateValueImpl(date.getYear(), date.getMonthValue(),
date.getDayOfMonth());
}
示例13: isEqual
import java.time.LocalDate; //导入方法依赖的package包/类
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
return ld.getYear() == d.getYear() + 1900 &&
ld.getMonthValue() == d.getMonth() + 1 &&
ld.getDayOfMonth() == d.getDate();
}
示例14: valueOf
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code Date} from a {@link LocalDate} object
* with the same year, month and day of month value as the given
* {@code LocalDate}.
* <p>
* The provided {@code LocalDate} is interpreted as the local date
* in the local time zone.
*
* @param date a {@code LocalDate} to convert
* @return a {@code Date} object
* @exception NullPointerException if {@code date} is null
* @since 1.8
*/
@SuppressWarnings("deprecation")
public static Date valueOf(LocalDate date) {
return new Date(date.getYear() - 1900, date.getMonthValue() -1,
date.getDayOfMonth());
}