List of usage examples for java.sql Timestamp getNanos
public int getNanos()
From source file:Main.java
public static void main(String[] args) { String text = "2011-10-02 18:48:05.123456"; Timestamp ts = Timestamp.valueOf(text); System.out.println(ts.getNanos()); }
From source file:Main.java
public static void main(String[] args) { java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2005-04-06 09:01:10"); System.out.println(ts2.getNanos()); }
From source file:Main.java
public static void main(String[] args) { long time = System.currentTimeMillis(); Date d = new Date(time); Timestamp t = new Timestamp(time); t.setNanos(123456789);/*from w w w. j a va2 s .co m*/ System.out.println(d); System.out.println(t); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'"); NumberFormat nf = new DecimalFormat("000000000"); System.out.println(df.format(t.getTime()) + nf.format(t.getNanos())); }
From source file:org.isatools.isatab.commandline.PersistenceShellCommand.java
public static void main(String[] args) { EntityTransaction transaction = null; try {/* ww w. j av a2s. com*/ Options clopts = createCommonOptions(); CommandLine cmdl = AbstractImportLayerShellCommand.parseCommandLine(clopts, args, PersistenceShellCommand.class); args = cmdl.getArgs(); if (args == null || args.length == 0) { printUsage(clopts); System.exit(1); } setup(args); setupLog4JPath(cmdl, null); // Need to initialize this here, otherwise above config will fail log = Logger.getLogger(PersistenceShellCommand.class); Properties hibProps = AbstractImportLayerShellCommand.getHibernateProperties(); hibProps.setProperty("hibernate.search.indexing_strategy", "manual"); hibProps.setProperty("hibernate.hbm2ddl.auto", "update"); hibProps.setProperty("hbm2ddl.drop", "false"); EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("BIIEntityManager", hibProps); EntityManager entityManager = entityManagerFactory.createEntityManager(); BIIObjectStore store = loadIsaTab(); log.info(i18n.msg("mapping_done_now_persisting", store.size())); ISATABPersister persister = new ISATABPersister(store, DaoFactory.getInstance(entityManager)); transaction = entityManager.getTransaction(); transaction.begin(); Timestamp ts = persister.persist(sourceDirPath); transaction.commit(); entityManager.close(); reindexStudies(store, hibProps); log.info("\n\n" + i18n.msg("mapping_done_data_saved_in_db")); log.info("\n\n" + i18n.msg("submission_done_ts_reported", "" + ts.getTime(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").format(ts) + "." + ts.getNanos()) + "\n"); System.exit(0); } catch (Exception ex) { String msg = "ERROR: problem while running the ISATAB loader: " + ex.getMessage(); if (log == null) { out.println(msg + "\n"); ex.printStackTrace(); } else { log.fatal(msg, ex); } System.exit(1); } }
From source file:Main.java
public static java.util.Date sqlTimestampToDate(Timestamp t) { return t != null ? new java.util.Date(Math.round(t.getTime() + t.getNanos() / 1000000D)) : null; }
From source file:Main.java
public static java.util.Date sqlTimestampToDate(Timestamp t) { return t != null ? new java.util.Date(Math.round((double) t.getTime() + (double) t.getNanos() / 1000000D)) : null;/*from www. jav a 2 s .c o m*/ }
From source file:com.msopentech.odatajclient.engine.data.ODataTimestamp.java
public static ODataTimestamp getInstance(final EdmSimpleType type, final Timestamp timestamp) { return new ODataTimestamp(new SimpleDateFormat(type.pattern()), new Date(timestamp.getTime()), timestamp.getNanos(), type == EdmSimpleType.DateTimeOffset); }
From source file:org.apache.phoenix.util.DateUtil.java
/** * Utility function to work around the weirdness of the {@link Timestamp} constructor. * This method takes the milli-seconds that spills over to the nanos part as part of * constructing the {@link Timestamp} object. * If we just set the nanos part of timestamp to the nanos passed in param, we * end up losing the sub-second part of timestamp. *///from www .jav a2 s . c o m public static Timestamp getTimestamp(long millis, int nanos) { if (nanos > MAX_ALLOWED_NANOS || nanos < 0) { throw new IllegalArgumentException("nanos > " + MAX_ALLOWED_NANOS + " or < 0"); } Timestamp ts = new Timestamp(millis); if (ts.getNanos() + nanos > MAX_ALLOWED_NANOS) { int millisToNanosConvertor = BigDecimal.valueOf(MILLIS_TO_NANOS_CONVERTOR).intValue(); int overFlowMs = (ts.getNanos() + nanos) / millisToNanosConvertor; int overFlowNanos = (ts.getNanos() + nanos) - (overFlowMs * millisToNanosConvertor); ts = new Timestamp(millis + overFlowMs); ts.setNanos(ts.getNanos() + overFlowNanos); } else { ts.setNanos(ts.getNanos() + nanos); } return ts; }
From source file:org.kuali.kra.proposaldevelopment.printing.xmlstream.ProposalDevelopmentXmlStream.java
public static java.util.Date toDate(java.sql.Timestamp timestamp) { long milliseconds = timestamp.getTime() + (timestamp.getNanos() / 1000000); return new java.util.Date(milliseconds); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
public static String getOffsetValueForTimestamp(Timestamp timestamp) { return getOffsetValueForTimestampParts(timestamp.getTime(), timestamp.getNanos()); }