Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:org.madsonic.ajax.PlayQueueService.java

public String savePlaylist() {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
    Player player = getCurrentPlayer(request, response);
    Locale locale = settingsService.getLocale();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);

    Date now = new Date();
    Playlist playlist = new Playlist();
    playlist.setUsername(securityService.getCurrentUsername(request));
    playlist.setCreated(now);/*from  ww  w. j a  va 2  s.  com*/
    playlist.setChanged(now);
    playlist.setPublic(false);
    playlist.setName(dateFormat.format(now));

    playlistService.createPlaylist(playlist);
    playlistService.setFilesInPlaylist(playlist.getId(), player.getPlayQueue().getFiles());
    return playlist.getName();
}

From source file:org.libreplan.web.common.Util.java

/**
 * Format specific <code>date</code> using the {@link DateFormat#DEFAULT} format and showing both date and time.
 *///  w  w  w. j a  va2  s.  c o m
public static String formatDateTime(Date dateTime) {
    return dateTime == null ? ""
            : DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locales.getCurrent())
                    .format(dateTime);
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

private void generateCertificateKeyUsageOnlyNonRepudiation() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPrivateKey = "30820277020100300d06092a864886f70d0101010500048202613082025d"
            + "02010002818100b342cf47e9e631e987a91cd281303c79be1ee94355e439"
            + "4a11606b740e30752eedd3a4d4c476963be7a329d7c92ed1f818f862389b"
            + "2c6bbec1b3f37e83a19aa05444d89c0d3bf7e567368320d1c1f4f1ef53c0"
            + "cb939f1c5cd01d4a8f4f637f0c4b16ff8e6ee4ba3beb4beddfc588ae1490"
            + "414dcaf1277f9c3287c9ea77897219020301000102818059a6a813c71ea1"
            + "07b21919990d931a2ba8b1bce7382593a13f5f815de15acac055a0eb669d"
            + "7ad157d458fdac35a97cc91f73d96b85ef8953357cd1e20be2de79470d67"
            + "841c79736d3938cf751816e214c176932d1ba26158d80da6f3f5ba61ac54"
            + "c1c9446435b2a0ef12b5cf25a03eabd931995175d40fe6aaef17b7b46bb8"
            + "01024100ff909d5f9ae1d2d3317137c9a9d775c0bdbf66b88b4a5d4893a4"
            + "ad9c7be321b78f00e76525e4269f0c1529750e87a4d4d6e5ac20e86a7095"
            + "c3441663ccb5f5f9024100b390f04e1944969dc3c05a4a699e6f9ae3e28b"
            + "e88d5d749271c849f4ca044648bff99de49257d07bcde0900a46294e233b"
            + "689bd447ce1280c1f3034416b5e521024100acb70c54677504a92c39eacd"
            + "045693c30db983ef665b7c8da7125d2e6b5f8612eab75eaab21feda60161"
            + "6fe2274eaeac150ba4f79c7b0ad97bdcd110e37179e9024100a17326ed41"
            + "80cedf68bad133e8c50059c69dd1e7b4fb1b2df4c9fddcefaa6a3b4d08b5"
            + "b366f537c9a8f148f143e62d9036013762e570de68107a5c2c633306a102"
            + "400cb68f16900107b2d2db6175807a05261caa05cf5bb14bcbafd9202cc4"
            + "5f75922185187c30f95d4ce5f44481d59174548e5bddd7bfe2896e6401a8" + "ed79797fed";

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100b3"
            + "42cf47e9e631e987a91cd281303c79be1ee94355e4394a11606b740e3075"
            + "2eedd3a4d4c476963be7a329d7c92ed1f818f862389b2c6bbec1b3f37e83"
            + "a19aa05444d89c0d3bf7e567368320d1c1f4f1ef53c0cb939f1c5cd01d4a"
            + "8f4f637f0c4b16ff8e6ee4ba3beb4beddfc588ae1490414dcaf1277f9c32" + "87c9ea778972190203010001";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "test@example.com";

    subjectBuilder.setCommonName("Valid certificate");
    subjectBuilder.setEmail(email);/*  w w w .j ava  2  s . co  m*/
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    // use TreeSet because we want a deterministic certificate (ie. hash should not change)
    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.NONREPUDIATION);

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH);
    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);

    BigInteger serialNumber = new BigInteger("1178c3b653829e895acb7100eb1f627", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 10:38:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, true /* critical */);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");
    certificateBuilder.addSubjectKeyIdentifier(true);

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("KeyUsageOnlyNonRepudiation", privateKey, null, chain);
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private WayPoint buildWay(Posicion pos, boolean linea, boolean showTime) {
    WayPoint way = new WayPoint(new LatLon(pos.getY(), pos.getX()));
    way.attr.put("time", dateFormat.format(pos.getMarcaTemporal().getTime()));
    String name = pos.getIdentificador();

    if (showTime) {
        name += " " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, LOCALE)
                .format(pos.getMarcaTemporal().getTime());
    }/*from w w w  .  j ava  2s  . com*/
    way.attr.put("name", name);

    way.setGarminCommentTime("time");
    way.drawLine = linea;
    return way;
}

From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java

public DateFormat getCommonFormatDate(final RequestData requestData, final Integer dateStyle,
        final Integer timeStyle) throws Exception {
    final Locale locale = requestData.getLocale();
    DateFormat formatter;//www.  ja v  a 2 s.c om
    if (timeStyle != null) {
        formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
    } else {
        formatter = DateFormat.getDateInstance(dateStyle, locale);
    }
    return formatter;
}

From source file:de.acosix.alfresco.mtsupport.repo.sync.TenantAwareChainingUserRegistrySynchronizer.java

protected void syncWithPlugin(final String id, final UserRegistry userRegistry, final boolean forceUpdate,
        final boolean isFullSync, final boolean splitTxns, final Set<String> visitedIds,
        final Set<String> allIds) {
    final String tenantDomain = TenantUtil.getCurrentDomain();
    final String batchId;
    final String technicalTenantIdentifier;
    if (TenantService.DEFAULT_DOMAIN.equals(tenantDomain)) {
        batchId = id;//from  w w  w .j  a v a 2s . c o m
        technicalTenantIdentifier = TenantUtil.DEFAULT_TENANT;
    } else {
        batchId = this.tenantService.getName(id);
        technicalTenantIdentifier = tenantDomain;
    }

    final String reservedBatchProcessNames[] = { SyncProcess.GROUP_ANALYSIS.getTitle(batchId),
            SyncProcess.USER_UPDATE_AND_CREATION.getTitle(batchId),
            SyncProcess.GROUP_CREATION_AND_ASSOCIATION_DELETION.getTitle(batchId),
            SyncProcess.GROUP_ASSOCIATION_CREATION.getTitle(batchId),
            SyncProcess.USER_ASSOCIATION.getTitle(batchId), SyncProcess.AUTHORITY_DELETION.getTitle(batchId) };

    this.notifySyncDirectoryStart(id, reservedBatchProcessNames);
    try {
        final Date groupLastModified = forceUpdate ? null
                : this.getMostRecentUpdateTime(GROUP_LAST_MODIFIED_ATTRIBUTE, id, splitTxns);
        final Date personLastModified = forceUpdate ? null
                : this.getMostRecentUpdateTime(PERSON_LAST_MODIFIED_ATTRIBUTE, id, splitTxns);

        if (groupLastModified != null) {
            LOGGER.info("Retrieving groups changed since {} from user registry {} of tenant {}",
                    DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault())
                            .format(groupLastModified),
                    id, technicalTenantIdentifier);
        } else {
            LOGGER.info("Retrieving all groups from user registry {} of tenant {}", id,
                    technicalTenantIdentifier);
        }

        final BatchProcessor<NodeDescription> groupAnalysisProcessor = new BatchProcessor<>(
                SyncProcess.GROUP_ANALYSIS.getTitle(batchId),
                this.transactionService.getRetryingTransactionHelper(),
                new UserRegistryNodeCollectionWorkProvider(userRegistry.getGroups(groupLastModified)),
                this.workerThreads, USER_REGISTRY_ENTITY_BATCH_SIZE, this.applicationEventPublisher,
                LogFactory.getLog(TenantAwareChainingUserRegistrySynchronizer.class), this.loggingInterval);
        final Analyzer groupAnalyzer = this.createAnalyzer(id, visitedIds, allIds);
        int groupProcessedCount = groupAnalysisProcessor.process(groupAnalyzer, splitTxns);

        this.processGroupCreationAndAssociationDeletion(id, batchId, groupAnalyzer, splitTxns);
        this.processGroupAssociationCreation(batchId, groupAnalyzer, splitTxns);

        if (personLastModified != null) {
            LOGGER.info("Retrieving users changed since {} from user registry {} of tenant {}",
                    DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault())
                            .format(personLastModified),
                    id, technicalTenantIdentifier);
        } else {
            LOGGER.info("Retrieving all users from user registry {} of tenant {}", id,
                    technicalTenantIdentifier);
        }

        final BatchProcessor<NodeDescription> userProcessor = new BatchProcessor<>(
                SyncProcess.USER_UPDATE_AND_CREATION.getTitle(batchId),
                this.transactionService.getRetryingTransactionHelper(),
                new UserRegistryNodeCollectionWorkProvider(userRegistry.getPersons(personLastModified)),
                this.workerThreads, USER_REGISTRY_ENTITY_BATCH_SIZE, this.applicationEventPublisher,
                LogFactory.getLog(TenantAwareChainingUserRegistrySynchronizer.class), this.loggingInterval);

        UserAccountInterpreter accountInterpreter;
        if (userRegistry instanceof EnhancedUserRegistry) {
            final String externalUserControl = this.externalUserControl.get(technicalTenantIdentifier);
            final String externalUserControlSubsystemName = this.externalUserControlSubsystemName
                    .get(technicalTenantIdentifier);
            if (Boolean.parseBoolean(externalUserControl) && id.equals(externalUserControlSubsystemName)) {
                accountInterpreter = ((EnhancedUserRegistry) userRegistry).getUserAccountInterpreter();
            } else {
                accountInterpreter = null;
            }
        } else {
            accountInterpreter = null;
        }

        final PersonWorker userWorker = this.createPersonWorker(id, visitedIds, allIds, accountInterpreter);
        int userProcessedCount = userProcessor.process(userWorker, splitTxns);

        this.processUserAssociation(batchId, groupAnalyzer, splitTxns);

        final long newLatestGroupModified = groupAnalyzer.getLatestModified();
        if (newLatestGroupModified > 0) {
            this.setMostRecentUpdateTime(GROUP_LAST_MODIFIED_ATTRIBUTE, id, newLatestGroupModified, splitTxns);
        }

        final long newLatestUserModified = userWorker.getLatestModified();
        if (newLatestUserModified > 0) {
            this.setMostRecentUpdateTime(PERSON_LAST_MODIFIED_ATTRIBUTE, id, newLatestUserModified, splitTxns);
        }

        final Pair<Integer, Integer> deletionCounts = this.processAuthorityDeletions(id, batchId, userRegistry,
                isFullSync, splitTxns);
        userProcessedCount += deletionCounts.getFirst().intValue();
        groupProcessedCount += deletionCounts.getSecond().intValue();

        visitedIds.add(id);

        final Object statusParams[] = { Integer.valueOf(userProcessedCount),
                Integer.valueOf(groupProcessedCount) };
        final String statusMessage = I18NUtil.getMessage("synchronization.summary.status", statusParams);

        LOGGER.info("Finished synchronizing users and groups with user registry {} of tenant {}", id,
                technicalTenantIdentifier);
        LOGGER.info(statusMessage);

        this.notifySyncDirectoryEnd(id, statusMessage);
    } catch (final RuntimeException e) {
        this.notifySyncDirectoryEnd(id, e);
        throw e;
    }
}

From source file:mitm.common.security.certificate.GenerateTestCertificates.java

/**
 * Generates a valid certificate/* ww  w  .jav  a2 s .  c  om*/
 * 
 * @throws Exception
 */
private void generateValidCertificateUppercaseEmail() throws Exception {
    X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder();

    String encodedPrivateKey = "30820278020100300d06092a864886f70d0101010500048202623082025e"
            + "02010002818100cc65b29afd51609fb23b4968518b54fe26f41519dfad63"
            + "1e1a5e240bbd57c133bcbf98572f533263294a31ba77b1f56abeeff2ce5e"
            + "02f0d1c07d23464a096e06ea8d643f7205b7002f9a6ba370493b27217cd0"
            + "e5e0577cf305557cdbe7c6602badba2ae297493e75f165d2d2340fad59b7"
            + "ee0d7c05b231379aad7854c873f703020301000102818100a90547e6a6a7"
            + "8e91405f8a5a7b640e8a8447bed340862eba8bef613b5bfd9f445b46cc80"
            + "fc1f7e4145b996d9ad75398e660a21ecc90d017b5203a911ccd373694628"
            + "11f5ef0e96152fa85a1e38901ef41ee675c4de1c7ce2ed2e2af84bb8f91b"
            + "9936f699071b24e58cf44746547fee72a7d869333267dbf17fa3ac4316c2"
            + "6b91024100ed1d02ad8294c88c6e1dd376080e2265b0b872c8913ec7d735"
            + "a07be89c5432b37417265e75e388122edb4d430adc116d745824e599f8c9"
            + "9e96a5ee09e8beaf7d024100dcad92821ff13e18942db08ca02d74ecb86a"
            + "1a48c9807be5a86197361851c259c89cfb46c78f51c52558230bfe0b437b"
            + "513908c6f6d0bd0b57a74edaba0b087f02410085ed81eab13c0a7ecf5fc7"
            + "65feacc51efd0f61be09d4151a68aee9edfc06ced06fbcf7ae1916587034"
            + "c927bdbb6f8be46ff7ad77865d70bc43c91b47bb8fa11d024100bfe28594"
            + "7465f692b4b60de0199fad1df1350169ed1cb59efa8cf148ee5899602c9a"
            + "a3bbe5e66f39b7c12da84ddc496f3f2f12bcbefcbe84d05100b61c335fcd"
            + "0240403c12a1c4e1536a877631b36a075bad052b8f94580b50617fe656a8"
            + "7b45d2ada4358483fea964b25500ab2579395bafe79fd315af79fe7706c9" + "1378aab9b2be";

    String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100cc"
            + "65b29afd51609fb23b4968518b54fe26f41519dfad631e1a5e240bbd57c1"
            + "33bcbf98572f533263294a31ba77b1f56abeeff2ce5e02f0d1c07d23464a"
            + "096e06ea8d643f7205b7002f9a6ba370493b27217cd0e5e0577cf305557c"
            + "dbe7c6602badba2ae297493e75f165d2d2340fad59b7ee0d7c05b231379a" + "ad7854c873f7030203010001";

    PrivateKey privateKey = decodePrivateKey(encodedPrivateKey);
    PublicKey publicKey = decodePublicKey(encodedPublicKey);

    X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder();

    String email = "TEST@EXAMPLE.COM";

    subjectBuilder.setCommonName("Valid certificate uppercase email");
    subjectBuilder.setEmail(email);
    subjectBuilder.setCountryCode("NL");
    subjectBuilder.setLocality("Amsterdam");
    subjectBuilder.setState("NH");

    AltNamesBuilder altNamesBuider = new AltNamesBuilder();
    altNamesBuider.setRFC822Names(email);

    X500Principal subject = subjectBuilder.buildPrincipal();
    GeneralNames altNames = altNamesBuider.buildAltNames();

    Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>();

    keyUsage.add(KeyUsageType.DIGITALSIGNATURE);
    keyUsage.add(KeyUsageType.KEYENCIPHERMENT);
    keyUsage.add(KeyUsageType.NONREPUDIATION);

    Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>();

    extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH);
    extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION);

    BigInteger serialNumber = new BigInteger("115fcde9dc082e7e9c8eef4cc69b94c", 16);

    Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK)
            .parse("21-Nov-2007 10:39:35");

    certificateBuilder.setSubject(subject);
    certificateBuilder.setAltNames(altNames, true);
    certificateBuilder.setKeyUsage(keyUsage, true);
    certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false);
    certificateBuilder.setNotBefore(DateUtils.addDays(now, -20));
    certificateBuilder.setNotAfter(DateUtils.addYears(now, 20));
    certificateBuilder.setPublicKey(publicKey);
    certificateBuilder.setSerialNumber(serialNumber);
    certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption");
    certificateBuilder.addSubjectKeyIdentifier(true);

    X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate);

    assertNotNull(certificate);

    certificates.add(certificate);

    Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate };

    keyStore.setKeyEntry("UppercaseEmail", privateKey, null, chain);
}

From source file:com.rogchen.common.xml.UtilDateTime.java

/**
 * Returns an initialized DateFormat object.
 *
 * @param dateTimeFormat optional format string
 * @param tz//from   w  ww. ja  va2s .c om
 * @param locale can be null if dateTimeFormat is not null
 * @return DateFormat object
 */
public static DateFormat toDateTimeFormat(String dateTimeFormat, TimeZone tz, Locale locale) {
    DateFormat df = null;
    if (dateTimeFormat == null) {
        df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
    } else {
        df = new SimpleDateFormat(dateTimeFormat);
    }
    df.setTimeZone(tz);
    return df;
}

From source file:ca.oson.json.Oson.java

public Oson setDateFormat(int dateStyle, int timeStyle, Locale locale) {
    options.setDateFormat(DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale));
    reset();//from   ww  w  .  j  a va 2s .com

    return this;
}

From source file:ca.oson.json.Oson.java

public <T> Oson setDateFormat(Class<T> type, int dateStyle, int timeStyle, Locale locale) {
    cMap(type).setDateFormat(DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale));
    reset();//from  w  w  w.  ja  va 2  s.co m

    return this;
}