本文整理汇总了Java中org.threeten.bp.LocalDateTime类的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime类的具体用法?Java LocalDateTime怎么用?Java LocalDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalDateTime类属于org.threeten.bp包,在下文中一共展示了LocalDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addRecord
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
public void addRecord()
{
if (recordnumber<neednumber)
{
recordnumber++;
have_record_all++;
}
if (recordnumber == neednumber){
//list add days from today to begin
long diff = 0;
LocalDateTime begindatetime=getBeginLocalDate();
LocalDateTime begindate=LocalDateTime.of(begindatetime.getYear(),begindatetime.getMonth(),
begindatetime.getDayOfMonth(),0,0);
diff = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)-begindate.toEpochSecond(ZoneOffset.UTC);
int diff_int = (int)diff;
Integer day = diff_int/60/60/24;
Log.e("Ken: dif for habits", String.valueOf(diff)+" "+diff+" "+day);
record.add(day);
}
}
示例2: durationFromAtoB
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
public static long durationFromAtoB(LocalDateTime A,LocalDateTime B)
{
String aString=LocalDateTime_to_String(A);
// reform the aString
String bString=LocalDateTime_to_String(B);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long diff=0;
try
{
Date aDate=df.parse(aString);
Date bDate=df.parse(bString);
diff = bDate.getTime() - aDate.getTime();//这样得到的差值是微秒级别
}
catch(ParseException e)
{
e.printStackTrace();
}
return diff;
}
示例3: durationFromNowtoB
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
public static long durationFromNowtoB(LocalDateTime B)
{
String endString=LocalDateTime_to_String(B);
long diff=0;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
Date nowDate=new Date();
Date endDate=df.parse(endString);
diff = endDate.getTime() - nowDate.getTime();
}
catch(ParseException e)
{
e.printStackTrace();
}
return diff;
}
示例4: mapPackageInfoToVersion
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test public void mapPackageInfoToVersion() {
LocalDateTime mockNow = LocalDateTime.of(2016, 1, 1, 0, 0);
PackageInfo packageInfo = MockPackageInfo.TEST;
App app = MockApp.TEST;
when(clock.now()).thenReturn(mockNow);
ToVersionMapper mapper = new ToVersionMapper(clock, app.id());
Version expectedVersion = Version.create(app.id(),
packageInfo.versionCode,
packageInfo.versionName,
mockNow);
Version version = mapper.map(MockPackageInfo.TEST);
assertThat(version).isEqualTo(expectedVersion);
}
示例5: resetAfterRestart
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
public void resetAfterRestart() {
LocalDateTime firstMockStart = LocalDateTime.of(2016, 1, 1, 0, 0, 0);
LocalDateTime firstMockEnd = LocalDateTime.of(2016, 1, 1, 0, 1, 0);
when(clock.now()).thenReturn(firstMockStart);
stopwatch.start();
when(clock.now()).thenReturn(firstMockEnd);
stopwatch.stop();
Duration firstActualDuration = Duration.between(firstMockStart, firstMockEnd);
Duration firstMeasuredDuration = stopwatch.getDuration();
assertThat(firstMeasuredDuration).isEqualTo(firstActualDuration);
LocalDateTime secondMockStart = LocalDateTime.of(2016, 1, 1, 0, 5, 0);
LocalDateTime secondMockEnd = LocalDateTime.of(2016, 1, 1, 0, 10, 0);
when(clock.now()).thenReturn(secondMockStart);
stopwatch.start();
when(clock.now()).thenReturn(secondMockEnd);
stopwatch.stop();
Duration secondActualDuration = Duration.between(secondMockStart, secondMockEnd);
Duration secondMeasuredDuration = stopwatch.getDuration();
assertThat(secondMeasuredDuration).isEqualTo(secondActualDuration);
}
示例6: addSessionReminder
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
public void addSessionReminder(@NonNull Session session) {
if (!isEnabled()) {
Timber.d("SessionsReminder is not enable, skip adding session");
return;
}
PendingIntent intent = createSessionReminderIntent(session);
LocalDateTime now = LocalDateTime.now();
LocalDateTime sessionStartTime = session.getFromTime().minusMinutes(3);
if (!sessionStartTime.isAfter(now)) {
Timber.w("Do not set reminder for passed session");
return;
}
Timber.d("Setting reminder on %s", sessionStartTime);
App.setExactAlarm(alarmManager, sessionStartTime.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(), intent);
}
示例7: should_convert_sessions_list_into_schedule
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_convert_sessions_list_into_schedule() {
// Given
LocalDateTime slot1 = LocalDateTime.of(2016, 3, 15, 8, 10);
LocalDateTime slot2 = slot1.plusHours(1);
LocalDateTime slot3 = slot2.plusHours(1);
LocalDateTime slot4 = slot1.plusDays(1);
Session session1 = new Session(1, "room1", singletonList(speaker1), "title1", "desc1", slot1, slot1.plusHours(1));
Session session2 = new Session(2, "room2", singletonList(speaker2), "title2", "desc2", slot1, slot1.plusHours(1));
Session session3 = new Session(3, "room1", singletonList(speaker3), "title3", "desc3", slot2, slot2.plusHours(1));
Session session4 = new Session(4, "room1", singletonList(speaker4), "title4", "desc4", slot3, slot3.plusHours(1));
Session session5 = new Session(5, "room1", singletonList(speaker5), "title5", "desc5", slot4, slot4.plusHours(1));
// When
Schedule result = appMapper.toSchedule(Arrays.asList(session1, session2, session3, session4, session5));
// Then
assertThat(result).hasSize(2);
assertThat(result.get(0).getDay()).isEqualTo(slot1.toLocalDate());
assertThat(result.get(0).getSlots()).hasSize(3);
assertThat(result.get(0).getSlots().get(0).getSessions()).containsAllOf(session1, session2);
assertThat(result.get(0).getSlots().get(0).getTime()).isEqualTo(slot1);
assertThat(result.get(0).getSlots().get(1).getSessions()).containsExactly(session3);
assertThat(result.get(1).getSlots()).hasSize(1);
assertThat(result.get(1).getSlots().get(0).getSessions()).containsExactly(session5);
}
示例8: should_restore_from_parcelable
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_restore_from_parcelable() {
// Given
LocalDateTime time = LocalDateTime.now();
List<Session> sessions = Arrays.asList(new Session(1, null, null, null, null, null, null), new Session(2, null, null, null, null, null, null), new Session(3, null, null, null, null, null, null));
ScheduleSlot slot = new ScheduleSlot(time, sessions);
// When
Parcel parcel = Parcel.obtain();
slot.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
ScheduleSlot fromParcel = ScheduleSlot.CREATOR.createFromParcel(parcel);
// Then
assertThat(fromParcel.getTime()).isEqualTo(time);
assertThat(fromParcel.getSessions()).hasSize(3);
}
示例9: should_convert_network_sessions_to_app_sessions
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_convert_network_sessions_to_app_sessions() {
// Given
LocalDateTime startAt = LocalDateTime.now();
Session session = new Session(1, startAt, 20, Room.NONE.id, singletonList(10), "title", "description");
Map<Integer, com.nilhcem.droidconde.data.app.model.Speaker> speakersMap = new HashMap<>();
speakersMap.put(10, new com.nilhcem.droidconde.data.app.model.Speaker(10, "ten", null, null, null, null, null, null));
// When
List<com.nilhcem.droidconde.data.app.model.Session> result = networkMapper.toAppSessions(singletonList(session), speakersMap);
// Then
assertThat(result).hasSize(1);
assertThat(result.get(0).getId()).isEqualTo(1);
assertThat(result.get(0).getFromTime()).isEqualTo(startAt);
assertThat(result.get(0).getToTime()).isEqualTo(startAt.plusMinutes(20));
assertThat(result.get(0).getRoom()).isEqualTo(Room.NONE.label);
assertThat(result.get(0).getSpeakers().get(0).getId()).isEqualTo(10);
assertThat(result.get(0).getSpeakers().get(0).getName()).isEqualTo("ten");
assertThat(result.get(0).getTitle()).isEqualTo("title");
assertThat(result.get(0).getDescription()).isEqualTo("description");
}
示例10: should_convert_network_sessions_to_app_sessions
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_convert_network_sessions_to_app_sessions() {
// Given
LocalDateTime startAt = LocalDateTime.now();
Session session = new Session(1, startAt, 20, Room.NONE.id, singletonList(10), "title", "description");
Map<Integer, com.nilhcem.droidconat.data.app.model.Speaker> speakersMap = new HashMap<>();
speakersMap.put(10, new com.nilhcem.droidconat.data.app.model.Speaker(10, "ten", null, null, null, null, null, null));
// When
List<com.nilhcem.droidconat.data.app.model.Session> result = networkMapper.toAppSessions(singletonList(session), speakersMap);
// Then
assertThat(result).hasSize(1);
assertThat(result.get(0).getId()).isEqualTo(1);
assertThat(result.get(0).getFromTime()).isEqualTo(startAt);
assertThat(result.get(0).getToTime()).isEqualTo(startAt.plusMinutes(20));
assertThat(result.get(0).getRoom()).isEqualTo(Room.NONE.label);
assertThat(result.get(0).getSpeakers().get(0).getId()).isEqualTo(10);
assertThat(result.get(0).getSpeakers().get(0).getName()).isEqualTo("ten");
assertThat(result.get(0).getTitle()).isEqualTo("title");
assertThat(result.get(0).getDescription()).isEqualTo("description");
}
示例11: should_remove_previous_session_when_adding_a_new_one_for_the_same_slot_time
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_remove_previous_session_when_adding_a_new_one_for_the_same_slot_time() {
// Given
LocalDateTime now = LocalDateTime.now();
Map<LocalDateTime, Integer> map = new HashMap<>();
map.put(now, 1);
memory.setSelectedSessions(map);
Session toAdd = new Session(3, null, null, null, null, now, now.plusMinutes(30));
// When
assertThat(memory.get(now)).isEqualTo(1);
memory.toggleSessionState(toAdd, true);
// Then
assertThat(memory.get(now)).isEqualTo(3);
}
示例12: should_restore_from_parcelable
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Test
public void should_restore_from_parcelable() {
// Given
List<Speaker> speakers = singletonList(new Speaker(1, null, null, null, null, null, null, null));
LocalDateTime fromTime = LocalDateTime.now().minusDays(1);
LocalDateTime toTime = fromTime.plusMinutes(45);
Session session = new Session(42, "ROOM1", speakers, "TITLE", "DESCRIPTION", fromTime, toTime);
// When
Parcel parcel = Parcel.obtain();
session.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
Session fromParcel = Session.CREATOR.createFromParcel(parcel);
// Then
assertThat(fromParcel.getId()).isEqualTo(42);
assertThat(fromParcel.getRoom()).isEqualTo("ROOM1");
assertThat(fromParcel.getSpeakers()).hasSize(1);
assertThat(fromParcel.getTitle()).isEqualTo("TITLE");
assertThat(fromParcel.getDescription()).isEqualTo("DESCRIPTION");
assertThat(fromParcel.getFromTime()).isEqualTo(fromTime);
assertThat(fromParcel.getToTime()).isEqualTo(toTime);
}
示例13: deserialize
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
@Override
public OffsetDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String src = json.getAsString();
// TODO 有些时间结构不符合标准,这里做兼容
try {
return OffsetDateTime.parse(src);
} catch (DateTimeParseException e) {
return OffsetDateTime.of(LocalDateTime.parse(src, formatterCompat), ZoneOffset.UTC);
}
}
示例14: AbstractsxObject
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
AbstractsxObject()
{
//initial to now
ID=0;
title="object";
state=1;
content="";
importance=0;
begin=LocalDateTime.now();
end=LocalDateTime.now().plusDays(10);
}
示例15: setBeginDate
import org.threeten.bp.LocalDateTime; //导入依赖的package包/类
public void setBeginDate(String date)
{
if (date.length()==16) date=date.concat(":00");
if (date.length()>19) date=date.substring(0,19);
DateTimeFormatter sf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
begin= LocalDateTime.parse(date, sf);
//Log.d("begindate",begin.toString());
}