List of usage examples for java.sql Date Date
public Date(long date)
From source file:org.hawkular.client.test.metrics.openshift.OpenshiftCollectionHistTest.java
/** * Save histogram data to file in csv format * @param filename file name with csv extension * @param histogram//from ww w. j a v a 2 s .c om * @param printToStdout set to true to also log the output in TestNG Reporter standard out */ public static void printHist(String filename, Map<Long, Integer> histogram, boolean printToStdout) { DateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("America/New_York")); PrintStream out = null; try { out = new PrintStream(new FileOutputStream(filename + ".csv")); for (Map.Entry<Long, Integer> e : histogram.entrySet()) { Date date = new Date(e.getKey()); String s = format.format(date) + "," + e.getValue(); out.println(s); if (printToStdout) { Reporter.log(s, true); } } } catch (Exception e) { Assert.fail("File IO error", e); } finally { IOUtils.closeQuietly(out); } }
From source file:net.kjmaster.cookiemom.booth.add.AddBoothDialogFragment.java
private void showDateTimeDialog() { // Create the dialog final Dialog mDateTimeDialog = new Dialog(getActivity()); // Inflate the root layout final RelativeLayout mDateTimeDialogView = (RelativeLayout) getActivity().getLayoutInflater() .inflate(R.layout.ui_date_time_dialog, null); // Grab widget instance final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView .findViewById(R.id.DateTimePicker); // Check is system is set to use 24h time (this doesn't seem to work as expected though) final String timeS = android.provider.Settings.System.getString(getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24); final boolean is24h = !(timeS == null || timeS.equals("12")); // Update demo TextViews when the "OK" button is clicked mDateTimeDialogView.findViewById(R.id.SetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mDateTimePicker.clearFocus(); // TODO Auto-generated method stub String eventDate = SimpleDateFormat.getDateInstance(DateFormat.LONG) .format(new Date(mDateTimePicker.getDateTimeMillis())); ((TextView) getActivity().findViewById(R.id.Date)).setText(eventDate); if (mDateTimePicker.is24HourView()) { ((TextView) getActivity().findViewById(R.id.Time)).setText( mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE)); } else { NumberFormat fmt = NumberFormat.getNumberInstance(); fmt.setMinimumIntegerDigits(2); ((TextView) getActivity().findViewById(R.id.Time)) .setText(fmt.format(mDateTimePicker.get(Calendar.HOUR)) + ":" + fmt.format(mDateTimePicker.get(Calendar.MINUTE)) + " " + (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM")); }//from w ww.j a v a 2 s . c o m hiddenDateTime.setText(String.valueOf(mDateTimePicker.getDateTimeMillis())); mDateTimeDialog.dismiss(); } }); // Cancel the dialog when the "Cancel" button is clicked mDateTimeDialogView.findViewById(R.id.CancelDialog).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimeDialog.cancel(); } }); // Reset Date and Time pickers when the "Reset" button is clicked mDateTimeDialogView.findViewById(R.id.ResetDateTime).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mDateTimePicker.reset(); } }); // Setup TimePicker mDateTimePicker.setIs24HourView(is24h); // No title on the dialog window mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // Set the dialog content view mDateTimeDialog.setContentView(mDateTimeDialogView); // Display the dialog mDateTimeDialog.show(); }
From source file:org.eclipse.dirigible.runtime.scripting.utils.DbUtils.java
public Date createDate(long value) { return new Date(value); }
From source file:org.efaps.dataexporter.AbstractDataExporterTestBase.java
/** * Adds the data./*from w w w . j ava2 s. c om*/ */ protected void addData() { this.exporter.addRow(new Date(this.dateReference - 2397984), new Integer(1), "Laptop", new Boolean(false), new Integer(1), new Double(799.78)); this.exporter.addRow(new Date(this.dateReference - 232042098), new Integer(2), "Mouse", new Boolean(true), new Integer(2), new Double(49.30)); this.exporter.addRow(new Date(this.dateReference - 234084277), new Integer(3), "Keyboard", new Boolean(false), new Integer(5), new Double(75)); }
From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java
@Override public long insertMutatiesFile(final java.util.Date dateFrom, final java.util.Date dateTo, final byte[] content) throws DAOException { try {//ww w.jav a 2s. co m KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("insert into bag_mutaties_file (" + " id," + " date_from," + " date_to," + " content" + ") values ((select nvl(max(id),0) + 1 from bag_mutaties_file),trunc(?),trunc(?),?)", new int[] { 1 }); ps.setDate(1, new Date(dateFrom.getTime())); ps.setDate(2, new Date(dateTo.getTime())); ps.setBytes(3, content); return ps; } }, keyHolder); return keyHolder.getKey().longValue(); } catch (DataAccessException e) { throw new DAOException(e); } }
From source file:cz.muni.fi.anatomytutor.backend.service.PracticeServiceImpl.java
@Override public void saveAnswer(AuthUserDto user, QuestionDto answer) { Answer answerEntity = new Answer(); answerEntity.setAuthor(AuthUserConvert.fromDtoToEntity(user)); Picture picture = new Picture(); picture.setId(answer.getPictureId()); picture.setName(answer.getPictureName()); picture.setSvg(answer.getPictureSvg()); answerEntity.setQuestionTerm(OptionConvert.fromDtoToEntity(answer.getQuestion(), picture)); answerEntity.setAnswerTerm(OptionConvert.fromDtoToEntity(answer.getAnswer(), picture)); Long now = System.currentTimeMillis(); answerEntity.setAnswerTime(new Time(now)); answerEntity.setAnswerDate(new Date(now)); answerDao.create(answerEntity);//from www . j a v a 2s . c o m }
From source file:tools.xor.logic.DefaultMutableJson.java
protected void checkDateField() throws JSONException { // create person JSONObject json = new JSONObject(); json.put("name", "DILIP_DALTON"); json.put("displayName", "Dilip Dalton"); json.put("description", "Software engineer in the bay area"); json.put("userName", "daltond"); // 1/1/15 7:00 PM EST final long CREATED_ON = 1420156800000L; Date createdOn = new Date(CREATED_ON); DateFormat df = new SimpleDateFormat(ImmutableJsonProperty.ISO8601_FORMAT); json.put("createdOn", df.format(createdOn)); Settings settings = new Settings(); settings.setEntityClass(Person.class); Person person = (Person) aggregateService.create(json, settings); assert (person.getId() != null); assert (person.getName().equals("DILIP_DALTON")); assert (person.getCreatedOn().getTime() == CREATED_ON); Object jsonObject = aggregateService.read(person, settings); json = (JSONObject) jsonObject;// ww w.j ava 2s. c om System.out.println("JSON string: " + json.toString()); assert (json.get("name").toString().equals("DILIP_DALTON")); assert ((json.get("createdOn")).toString().equals("2015-01-01T16:00:00.000-0800")); }
From source file:org.hibernate.search.test.performance.scenario.TestExecutor.java
protected void initDatabase(TestContext ctx) { log("starting initialize database"); ctx.initDatabaseStopWatch.start();// www.j ava 2 s . co m BatchSupport batchSupport = new BatchSupport(ctx.sessionFactory, ctx.initialOffset); batchSupport.execute("insert into author(id, name) values(?, ?)", ctx.initialAuthorCount, new BatchCallback() { @Override public void initStatement(PreparedStatement ps, long id) throws SQLException { ps.setLong(1, id); ps.setString(2, "author" + id); } }); batchSupport.execute( "insert into book(id, title, summary, rating, totalSold, publicationDate) values(?, ?, ?, ?, ?, ?)", ctx.initialBookCount, new BatchCallback() { @Override public void initStatement(PreparedStatement ps, long id) throws SQLException { ps.setLong(1, id); ps.setString(2, "title" + id); ps.setString(3, reverse(SUMMARIES[(int) (id % SUMMARIES.length)])); ps.setLong(4, -1); ps.setLong(5, -1); ps.setDate(6, new Date(PUBLICATION_DATE_ZERO.getTime())); } }); batchSupport.execute("insert into book_author(book_id, authors_id) values(?, ?)", ctx.initialBookCount, new BatchCallback() { @Override public void initStatement(PreparedStatement ps, long id) throws SQLException { ps.setLong(1, id); ps.setLong(2, ctx.initialOffset + (id % ctx.initialAuthorCount)); } }); ctx.initDatabaseStopWatch.stop(); }
From source file:com.xumpy.thuisadmin.dao.BedragenDaoTest.java
@Before @Transactional(value = "jpaTransactionManager") public void setUpBedragen() { personen = personenDao.findOne(1);/* w w w. ja v a2 s.c om*/ groep = groepenDao.findOne(1); rekening = rekeningenDao.findOne(1); bedrag = Mockito.mock(Bedragen.class); when(bedrag.getPk_id()).thenReturn(BEDRAG_PK_ID); when(bedrag.getBedrag()).thenReturn(new BigDecimal(200)); when(bedrag.getPersoon()).thenReturn(personen); when(bedrag.getGroep()).thenReturn(groep); when(bedrag.getDatum()).thenReturn(new Date(new java.util.Date().getTime())); when(bedrag.getOmschrijving()).thenReturn("test bedrag"); when(bedrag.getRekening()).thenReturn(rekening); }
From source file:org.eluder.coveralls.maven.plugin.json.JsonWriterTest.java
@SuppressWarnings("rawtypes") @Test// w ww .jav a 2 s.co m public void testWriteStartAndEnd() throws Exception { JsonWriter writer = new JsonWriter(job(), file); try { writer.onBegin(); writer.onComplete(); } finally { writer.close(); } String content = TestIoUtil.readFileContent(file); Map<String, Object> jsonMap = stringToJsonMap(content); assertEquals("service", jsonMap.get("service_name")); assertEquals("job123", jsonMap.get("service_job_id")); assertEquals("build5", jsonMap.get("service_number")); assertEquals("http://ci.com/build5", jsonMap.get("service_build_url")); assertEquals("foobar", ((Map) jsonMap.get("environment")).get("custom_property")); assertEquals("master", jsonMap.get("service_branch")); assertEquals("pull10", jsonMap.get("service_pull_request")); assertEquals(new SimpleDateFormat(JsonWriter.TIMESTAMP_FORMAT).format(new Date(TEST_TIME)), jsonMap.get("run_at")); assertEquals("af456fge34acd", ((Map) jsonMap.get("git")).get("branch")); assertEquals("aefg837fge", ((Map) ((Map) jsonMap.get("git")).get("head")).get("id")); assertEquals(0, ((Collection<?>) jsonMap.get("source_files")).size()); }