Java Code Examples for java.util.Date#setTime()

The following examples show how to use java.util.Date#setTime() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Test
public void succeedsWhenMaxSentAndAuthTimeWithCustomLeeway() {
    String token = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC0xMjMiXSwiZXhwIjoxNTY3NDg2ODAwLCJpYXQiOjE1NjczMTQwMDAsIm5vbmNlIjoiYTU5dms1OTIiLCJhenAiOiJ0b2tlbnMtdGVzdC0xMjMiLCJhdXRoX3RpbWUiOjE1NjczMTQwMDB9.AbSYZ_Tu0-ZelCRPuu9jOd9y1M19yIlk8bjSQDVVgAekRZLdRA_T_gi_JeWyFysKZVpRcHC1YJhTH4YH8CCMRTwviq3woIsLmdUecjydyZkHcUlhHXj2DbC15cyELalPNe3T9eZ4ySwk9qRJSOkjBAgXAT0a7M6rwri6QHnL0WxTLX4us4rGu8Ui3kuf1WaZH9DNoeWYs1N3xUclockTkRKaqXnuKjnwSVmsuwxFSlnIPJOiMUUZksiaBq_OUvOkB-dEG7OFiDX9XWj1m62yBHkvZHun8LBr9VW3mt1IrcBdbbtzjWwfn6ioK2c4dbtPFhuYohXsmRDaSekP63Dmlw3A";

    Integer maxAge = 120;
    Integer customLeeway = 120;

    // set clock to September 1, 2019 5:00:00 AM GMT
    Date clock = new Date(1567314000000L);
    clock.setTime(clock.getTime() + ((maxAge + customLeeway - 1) * 1000));

    IdTokenVerifier.Options options = configureOptions(token);
    options.setClock(clock);
    options.setMaxAge(maxAge);
    options.setClockSkew(customLeeway);

    new IdTokenVerifier().verify(token, options);
}
 
Example 2
public void testDatesTDD() {
    long[]  data = { 1557010799726L,
    1557010799651L,
    1557010799393L,
    1557010799289L,
    1557010799109L,
    1556924400709L,
    1556924400521L,
    1556924400353L,
    1556924399948L,
    1556924399910L };

    for (long datum : data) {
        Date d = new Date();
        d.setTime(datum);

        System.out.println("Date: " + d);
    }




}
 
Example 3
public static File generatePicturePath()
{
    try
    {
        File storageDir = getAlbumDir();
        Date date = new Date();
        date.setTime(System.currentTimeMillis() + Utilities.random.nextInt(1000) + 1);
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(date);
        return new File(storageDir, "IMG_" + timeStamp + ".jpg");
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
    return null;
}
 
Example 4
private TimePeriod getTimePeriod(int noOfHours) throws MegatronException {
        // DEBUG
//        try {
//            Date startDate = DateUtil.parseDateTime(DateUtil.DATE_TIME_FORMAT_WITH_SECONDS, "2013-01-01 00:00:00");
//            Date endDate = DateUtil.parseDateTime(DateUtil.DATE_TIME_FORMAT_WITH_SECONDS, "2014-01-01 23:59:59");
//            return new TimePeriod(startDate, endDate);
//        } catch (ParseException e) {
//            throw new MegatronException("Cannot parse date.", e);
//        }
        
        DateTime now = new DateTime();
        DateTime endDateTime = now.hourOfDay().roundFloorCopy();
        DateTime startDateTime = endDateTime.minusHours(noOfHours);
        // set end time to 23:59:59
        Date endDate = endDateTime.toDate();
        endDate.setTime(endDate.getTime() - 1000L);
        return new TimePeriod(startDateTime.toDate(), endDate);
    }
 
Example 5
@Test
public void succeedsWhenExpClaimInPastButWithinDefaultLeeway() {
    String token = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC0xMjMiXSwiZXhwIjoxNTY3MzE0MDAwLCJpYXQiOjE1NjczMTQwMDAsIm5vbmNlIjoiYTU5dms1OTIiLCJhenAiOiJ0b2tlbnMtdGVzdC0xMjMiLCJhdXRoX3RpbWUiOjE1NjczMTQwMDB9.uDn-4wtiigGddUw2kis_QyfDE3w75rWvu9NolMgD3b7l4_fedhQOk-z_mYID588ZXpnpLRKKiD5I2IFsXl7Qcc10rx1LIZxNqdzyc3VrgFf677x7fFZ4guR2WalH-zdJEluruMRdCIFQczIjXnGKPHGQ8gPH1LRozv43dl-bO2viX6MU4pTgNq3GIsU4ureyHrx1o9JSqF4b_RzuYvVWVVX7ABC2csMJP_ocVbEIQjUBhp1V7VcQY-Zgq0prk_HvY13g8FxK4KvSza637ZWAfonn599SKuy22PeMJqDfd64SbunWrt-mKBz9PHeAo9t4LJPLsAqSd3IQ2aJTsnqJRA";

    // set clock to September 1, 2019 5:00:00 AM GMT
    Date clock = new Date(1567314000000L);
    clock.setTime(clock.getTime() + ((DEFAULT_CLOCK_SKEW - 1) * 1000));

    IdTokenVerifier.Options options = configureOptions(token);
    options.setClock(clock);

    new IdTokenVerifier().verify(token, options);
}
 
Example 6
Source Project: steady   File: SymmetricBindingHandler.java    License: Apache License 2.0 5 votes vote down vote up
private String setupEncryptedKey(TokenWrapper wrapper, Token sigToken) throws WSSecurityException {
    WSSecEncryptedKey encrKey = this.getEncryptedKeyBuilder(wrapper, sigToken);
    String id = encrKey.getId();
    byte[] secret = encrKey.getEphemeralKey();

    Date created = new Date();
    Date expires = new Date();
    expires.setTime(created.getTime() + 300000);
    SecurityToken tempTok = new SecurityToken(
                    id, 
                    encrKey.getEncryptedKeyElement(),
                    created, 
                    expires);
    
    
    tempTok.setSecret(secret);
    
    // Set the SHA1 value of the encrypted key, this is used when the encrypted
    // key is referenced via a key identifier of type EncryptedKeySHA1
    tempTok.setSHA1(getSHA1(encrKey.getEncryptedEphemeralKey()));
    
    tokenStore.add(tempTok);
    
    String bstTokenId = encrKey.getBSTTokenId();
    //If direct ref is used to refer to the cert
    //then add the cert to the sec header now
    if (bstTokenId != null && bstTokenId.length() > 0) {
        encrKey.prependBSTElementToHeader(secHeader);
    }
    return id;
}
 
Example 7
Source Project: uavstack   File: DateTimeHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static Date getTomorrow() {

        Date date = new Date();
        long time = (date.getTime() / 1000) + 60 * 60 * 24;
        date.setTime(time * 1000);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = format.parse(format.format(date));
        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return date;
    }
 
Example 8
Source Project: FlipGank   File: DataManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取前一天的日期字符串, 例如输入 2016/12/16
 * @return 前一天的时间 2016/12/15
 */
private static String dayBack(String dayStr) {
    int[] dayInts = dayStr2Int(dayStr);
    Calendar calendar = Calendar.getInstance();
    calendar.set(dayInts[0], dayInts[1] - 1, dayInts[2]);
    Date date = calendar.getTime();
    long time = date.getTime() - A_DAY;
    date.setTime(time);
    calendar.setTime(date);

    return dayInt2Str(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
}
 
Example 9
Source Project: brooklyn-server   File: TimeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseDateToStringWithMillisecond() {
    Date d = new Date();
    // clear seconds, but add a milli - to ensure not just toString formatting but also seconds computation
    d.setTime(d.getTime() - (d.getTime() % 60000) + 1);
    assertDatesParseToEqual(d.toString(), Time.makeDateStampString(d.getTime()));
}
 
Example 10
@Test
public void testDaysBeforeNowWithRealDate(){
    Date date = new Date();
    date.getTime();
    Date dateMinusOneDay = new Date();
    long millisecondsInOneDay = 86400000L;
    dateMinusOneDay.setTime(date.getTime() - millisecondsInOneDay);
    Calendar cal = Calendar.getInstance();
    cal.setTime(dateMinusOneDay);
    date = ExtDateTimeUtils.daysBeforeNow(1);
    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(date);
    assertEquals("1 day before input date ",cal.get(Calendar.DAY_OF_MONTH),cal2.get(Calendar.DAY_OF_MONTH));
}
 
Example 11
protected NotifierConfig getUpdatedConfig() throws ApsSystemException, ParseException {
	NotifierConfig notifierConfig = this.getConfig();

	Date startDate = DateConverter.parseDate(this.getStartDate(), DATE_FORMAT);
	long time = startDate.getTime() + this.getHour() * 3600000l + this.getMinute() * 60000l;
	startDate.setTime(time);
	notifierConfig.setStartScheduler(startDate);

	return notifierConfig;
}
 
Example 12
Source Project: android_9.0.0_r45   File: AppOpsService.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpTimesLocked(PrintWriter pw, String firstPrefix, String prefix, long[] times,
        long now, SimpleDateFormat sdf, Date date) {
    boolean hasTime = false;
    for (int i = 0; i < _NUM_UID_STATE; i++) {
        if (times[i] != 0) {
            hasTime = true;
            break;
        }
    }
    if (!hasTime) {
        return;
    }
    boolean first = true;
    for (int i = 0; i < _NUM_UID_STATE; i++) {
        if (times[i] != 0) {
            pw.print(first ? firstPrefix : prefix);
            first = false;
            pw.print(UID_STATE_NAMES[i]);
            pw.print(" = ");
            date.setTime(times[i]);
            pw.print(sdf.format(date));
            pw.print(" (");
            TimeUtils.formatDuration(times[i]-now, pw);
            pw.println(")");
        }
    }
}
 
Example 13
@Override
protected void doResponseHeaders(HttpServletResponse response, Resource resource, String mimeType) {
    super.doResponseHeaders(response, resource, mimeType);
    Date expiresAt = new Date();
    expiresAt.setTime(new Date().getTime() + (seconds * 1000));
    response.setHeader("expires", dateFormat.format(expiresAt));
}
 
Example 14
Source Project: cloudstack   File: VmwareHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static XMLGregorianCalendar getXMLGregorianCalendar(final Date date, final int offsetSeconds) throws DatatypeConfigurationException {
    if (offsetSeconds > 0) {
        date.setTime(date.getTime() - offsetSeconds * 1000);
    }
    final GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
}
 
Example 15
private static void loadSampleThreads(String tableName) {
    try {
        long time1 = (new Date()).getTime() - (7 * 24 * 60 * 60 * 1000); // 7
        // days
        // ago
        long time2 = (new Date()).getTime() - (14 * 24 * 60 * 60 * 1000); // 14
        // days
        // ago
        long time3 = (new Date()).getTime() - (21 * 24 * 60 * 60 * 1000); // 21
        // days
        // ago

        Date date1 = new Date();
        date1.setTime(time1);

        Date date2 = new Date();
        date2.setTime(time2);

        Date date3 = new Date();
        date3.setTime(time3);

        dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        Table table = dynamoDB.getTable(tableName);

        System.out.println("Adding data to " + tableName);

        Item item = new Item().withPrimaryKey("ForumName", "Amazon DynamoDB")
            .withString("Subject", "DynamoDB Thread 1").withString("Message", "DynamoDB thread 1 message")
            .withString("LastPostedBy", "User A").withString("LastPostedDateTime", dateFormatter.format(date2))
            .withNumber("Views", 0).withNumber("Replies", 0).withNumber("Answered", 0)
            .withStringSet("Tags", new HashSet<String>(Arrays.asList("index", "primarykey", "table")));
        table.putItem(item);

        item = new Item().withPrimaryKey("ForumName", "Amazon DynamoDB").withString("Subject", "DynamoDB Thread 2")
            .withString("Message", "DynamoDB thread 2 message").withString("LastPostedBy", "User A")
            .withString("LastPostedDateTime", dateFormatter.format(date3)).withNumber("Views", 0)
            .withNumber("Replies", 0).withNumber("Answered", 0)
            .withStringSet("Tags", new HashSet<String>(Arrays.asList("index", "partitionkey", "sortkey")));
        table.putItem(item);

        item = new Item().withPrimaryKey("ForumName", "Amazon S3").withString("Subject", "S3 Thread 1")
            .withString("Message", "S3 Thread 3 message").withString("LastPostedBy", "User A")
            .withString("LastPostedDateTime", dateFormatter.format(date1)).withNumber("Views", 0)
            .withNumber("Replies", 0).withNumber("Answered", 0)
            .withStringSet("Tags", new HashSet<String>(Arrays.asList("largeobjects", "multipart upload")));
        table.putItem(item);

    }
    catch (Exception e) {
        System.err.println("Failed to create item in " + tableName);
        System.err.println(e.getMessage());
    }

}
 
Example 16
private static void loadSampleReplies(String tableName) {
    try {
        // 1 day ago
        long time0 = (new Date()).getTime() - (1 * 24 * 60 * 60 * 1000);
        // 7 days ago
        long time1 = (new Date()).getTime() - (7 * 24 * 60 * 60 * 1000);
        // 14 days ago
        long time2 = (new Date()).getTime() - (14 * 24 * 60 * 60 * 1000);
        // 21 days ago
        long time3 = (new Date()).getTime() - (21 * 24 * 60 * 60 * 1000);

        Date date0 = new Date();
        date0.setTime(time0);

        Date date1 = new Date();
        date1.setTime(time1);

        Date date2 = new Date();
        date2.setTime(time2);

        Date date3 = new Date();
        date3.setTime(time3);

        dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        Table table = dynamoDB.getTable(tableName);

        System.out.println("Adding data to " + tableName);

        // Add threads.

        Item item = new Item().withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 1")
            .withString("ReplyDateTime", (dateFormatter.format(date3)))
            .withString("Message", "DynamoDB Thread 1 Reply 1 text").withString("PostedBy", "User A");
        table.putItem(item);

        item = new Item().withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 1")
            .withString("ReplyDateTime", dateFormatter.format(date2))
            .withString("Message", "DynamoDB Thread 1 Reply 2 text").withString("PostedBy", "User B");
        table.putItem(item);

        item = new Item().withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 2")
            .withString("ReplyDateTime", dateFormatter.format(date1))
            .withString("Message", "DynamoDB Thread 2 Reply 1 text").withString("PostedBy", "User A");
        table.putItem(item);

        item = new Item().withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 2")
            .withString("ReplyDateTime", dateFormatter.format(date0))
            .withString("Message", "DynamoDB Thread 2 Reply 2 text").withString("PostedBy", "User A");
        table.putItem(item);

    }
    catch (Exception e) {
        System.err.println("Failed to create item in " + tableName);
        System.err.println(e.getMessage());

    }
}
 
Example 17
private void updateChartData() {
    tradeStatisticsByCurrency.setAll(tradeStatisticsManager.getObservableTradeStatisticsSet().stream()
            .filter(e -> showAllTradeCurrenciesProperty.get() || e.getCurrencyCode().equals(getCurrencyCode()))
            .collect(Collectors.toList()));

    // Generate date range and create sets for all ticks
    itemsPerInterval = new HashMap<>();
    Date time = new Date();
    for (long i = maxTicks + 1; i >= 0; --i) {
        Set<TradeStatistics2> set = new HashSet<>();
        Pair<Date, Set<TradeStatistics2>> pair = new Pair<>((Date) time.clone(), set);
        itemsPerInterval.put(i, pair);
        time.setTime(time.getTime() - 1);
        time = roundToTick(time, tickUnit);
    }

    // Get all entries for the defined time interval
    tradeStatisticsByCurrency.forEach(e -> {
        for (long i = maxTicks; i > 0; --i) {
            Pair<Date, Set<TradeStatistics2>> p = itemsPerInterval.get(i);
            if (e.getTradeDate().after(p.getKey())) {
                p.getValue().add(e);
                break;
            }
        }
    });

    // create CandleData for defined time interval
    List<CandleData> candleDataList = itemsPerInterval.entrySet().stream()
            .filter(entry -> entry.getKey() >= 0 && !entry.getValue().getValue().isEmpty())
            .map(entry -> getCandleData(entry.getKey(), entry.getValue().getValue()))
            .sorted(Comparator.comparingLong(o -> o.tick))
            .collect(Collectors.toList());

    priceItems.setAll(candleDataList.stream()
            .map(e -> new XYChart.Data<Number, Number>(e.tick, e.open, e))
            .collect(Collectors.toList()));

    volumeItems.setAll(candleDataList.stream()
            .map(e -> new XYChart.Data<Number, Number>(e.tick, e.accumulatedAmount, e))
            .collect(Collectors.toList()));
}
 
Example 18
private void dingdingSync(DingdingQywxSyncRecord record) throws Exception {
        Application app = ThisApplication.context().applications().randomWithWeight(x_organization_assemble_control.class.getName());
        //开始分页查询人员
        boolean hasNextPerson = true;
        int personPageSize = 50;
        //开始时间和结束时间
        Date fromDate = new Date();
        fromDate.setTime(record.getDateFrom());
        Date toDate =new Date();
        toDate.setTime(record.getDateTo());
        //先删除
        deleteDingdingAttendance(fromDate, toDate);
        //人员查询地址
        String uri = "person/list/(0)/next/50";
        //钉钉考勤同步接口地址
        String dingdingUrl = "https://oapi.dingtalk.com/attendance/list?access_token=" + Config.dingding().corpAccessToken();
        int saveNumber = 0;
        while (hasNextPerson) {
            logger.info("uri:"+ uri);
            List<Person> list = ThisApplication.context().applications().getQuery(false, app, uri).getDataAsList(Person.class);
            if (list != null && list.size() > 0) {
                //钉钉用户id
                List<String> ddUsers = list.stream().filter(person -> StringUtils.isNotEmpty(person.getDingdingId()))
                        .map(Person::getDingdingId).collect(Collectors.toList());
                if (ListTools.isNotEmpty(ddUsers)) {
                    //分页查询
                    int page = 0;
                    boolean hasMoreResult = true;
                    while (hasMoreResult) {
                        DingdingAttendancePost post = new DingdingAttendancePost();
                        //post传入 时间(时间间隔不能超过7天) 人员(人员数量不能超过50个)
                        post.setLimit(50L);
                        post.setOffset(page * 50L);//从0开始翻页
                        //这里的开始时间和结束时间 查询的是钉钉返回结果中的workDate
                        //查询考勤打卡记录的起始工作日
                        post.setWorkDateFrom(DateTools.format(fromDate));
                        //查询考勤打卡记录的结束工作日
                        post.setWorkDateTo(DateTools.format(toDate));
                        post.setUserIdList(ddUsers);
                        DingdingAttendanceResult result = HttpConnection.postAsObject(dingdingUrl, null, post.toString(), DingdingAttendanceResult.class);
                        if (result.errcode != null && result.errcode == 0) {
                            List<DingdingAttendanceResultItem> resultList = result.getRecordresult();
                            saveDingdingAttendance(resultList, list);
                            saveNumber += resultList.size();
                            if (result.hasMore) {
                                page++;
                            } else {
                                logger.info("同步钉钉考勤结束。。。。。。。。。。。。。。。。");
                                hasMoreResult = false;
                            }
                        } else {
                            //请求结果异常 结束
                            throw new DingDingRequestException(result.errmsg);
                        }
                    }
                }
                //是否还有更多用户
                if (list.size() < personPageSize) {
                    logger.info("同步钉钉考勤 没有更多用户了,结束。。。。。。。。。。。。。。。");
                    hasNextPerson = false;
                    updateSyncRecord(record, null);
                } else {
                    //还有更多用户继续查询
                    uri = Applications.joinQueryUri("person","list", list.get(list.size() - 1).getDistinguishedName(), "next", "50");
//                    uri = "person/list/" + list.get(list.size() - 1).getDistinguishedName() + "/next/50";
                }
            } else {
                //没有用户查询到结束
                logger.info("同步钉钉考勤 查询不到用户了,结束。。。。。。。。。。。。。。。");
                hasNextPerson = false;
                updateSyncRecord(record, null);
            }
        }
        logger.info("结束 插入:"+saveNumber+" 条");
        //插入数据成功 开始统计程序

        boolean hasNextDate = true;
        Date statisticDate = fromDate;
        while (hasNextDate) {
            logger.info("发起钉钉考勤数据统计, date:"+ DateTools.format(statisticDate));
            ThisApplication.personStatisticQueue.send(statisticDate);
            ThisApplication.unitStatisticQueue.send(statisticDate);
            if (!isSameDay(statisticDate, toDate)) {
                statisticDate = DateTools.addDay(statisticDate, 1);
            }else {
                hasNextDate = false;
            }
        }
        logger.info("发起数据统计程序 完成。。。。。。。。。。");
    }
 
Example 19
private static void loadSampleReplies(String tableName) {
    try {
        // 1 day ago
        long time0 = (new Date()).getTime() - (1 * 24 * 60 * 60 * 1000); 
        // 7 days ago
        long time1 = (new Date()).getTime() - (7 * 24 * 60 * 60 * 1000); 
        // 14 days ago
        long time2 = (new Date()).getTime() - (14 * 24 * 60 * 60 * 1000); 
        // 21 days ago
        long time3 = (new Date()).getTime() - (21 * 24 * 60 * 60 * 1000);

        Date date0 = new Date();
        date0.setTime(time0);

        Date date1 = new Date();
        date1.setTime(time1);

        Date date2 = new Date();
        date2.setTime(time2);

        Date date3 = new Date();
        date3.setTime(time3);

        dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        Table table = dynamoDB.getTable(tableName);

        System.out.println("Adding data to " + tableName);

        // Add threads.

        Item item = new Item()
            .withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 1")
            .withString("ReplyDateTime", (dateFormatter.format(date3)))
            .withString("Message", "DynamoDB Thread 1 Reply 1 text")
            .withString("PostedBy", "User A");
        table.putItem(item);

        item = new Item()
            .withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 1")
            .withString("ReplyDateTime", dateFormatter.format(date2))
            .withString("Message", "DynamoDB Thread 1 Reply 2 text")
            .withString("PostedBy", "User B");
        table.putItem(item);

        item = new Item()
            .withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 2")
            .withString("ReplyDateTime", dateFormatter.format(date1))
            .withString("Message", "DynamoDB Thread 2 Reply 1 text")
            .withString("PostedBy", "User A");
        table.putItem(item);

        item = new Item()
            .withPrimaryKey("Id", "Amazon DynamoDB#DynamoDB Thread 2")
            .withString("ReplyDateTime", dateFormatter.format(date0))
            .withString("Message", "DynamoDB Thread 2 Reply 2 text")
            .withString("PostedBy", "User A");
        table.putItem(item);

    } catch (Exception e) {
        System.err.println("Failed to create item in " + tableName);
        System.err.println(e.getMessage());

    }
}
 
Example 20
/**
 * This method returns a Date object that is accurate to within one second.
 * If a thread calls this method to get a Date and it's been less than 1
 * second since a new Date was created, this method simply gives out the
 * same Date again so that the system doesn't spend time creating Date
 * objects unnecessarily.
 * @param systime The time
 * @return the date object
 */
private static Date getDate(long systime) {
    Date date = localDate.get();
    date.setTime(systime);
    return date;
}