Convert Formated date to TimeStamp?
Hello
How can I convert a string like '20090424 21:28:12 ' timestamp?
I can't find the standard java SimpleDateFormat class and the blackberry version is not as even.
How can I do this conversion?
Thank you very much.
If you mean by "Timestamp" milliseconds since the time (midnight 1970-01-01), I do it manually.
First of all, I break the chain in the year of substrings, month, day, hour, minute, second. Then:
Calendar c = Calendar.getInstance("UTC"); c.set(Calendar.YEAR, Integer.parseInt(year)); c.set(Calendar.MONTH, Integer.parseInt(month) - 1); c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day)); c.set(Calendar.HOUR, Integer.parseInt(hour)); c.set(Calendar.MINUTE, Integer.parseInt(minute)); c.set(Calendar.SECOND, Integer.parseInt(second)); long millisSinceEpoch = c.getTime().getTime();
Note the - 1 in the month, JAVA months are 0-based.
Note the "UTC" in Calendar.GetInstance (), without it, you would get a calendar for the local time zone (and midnight 1970-01-01 is not zero, may not matter to you).
And of course, there could be a better way.
Cheers, Barak.
Tags: BlackBerry Developers
Similar Questions
-
DATE in TIMESTAMP data type conversion
Hello
My question is this:
1. I have a variable of type DATE, which I attribute the value of SYSDATE
2. I want to find * «today» *, truncated to DATEmydatevar DATE:= SYSDATE;
TRUNC function returns the DATE data type. So I get to the point for example 2 *'2010-01-13 00:00:00 ' *.TRUNC (mydatevar, 'DD')
3. I want to assign the value of the point 2, to a variable of type TIMESTAMP
implicitly that will convert the variable DATE to TIMESTAMP.mytimestampvar TIMESTAMP := mydatevar;
Problem: when converting (implicit and explicit conversion with a format mask), I lose hours "00" and "00" minutes and receive something like this: "10 January 13 * 12 *. 00.00.000000000 AM.
Question: How can I convert a DATE to TIMESTAMP keeping the hours and minutes zeros?
Why I need this conversion: I have a table with one "column1" TIMESTAMP column (0) and I take only the rows of the table, where 'column1' is in the range of today 12:00 in the morning until now (what time it is).
Features of the database NLS:
Session settings are the same.PARAMETER VALUE NLS_LANGUAGE AMERICAN NLS_TERRITORY AMERICA NLS_CURRENCY $ NLS_ISO_CURRENCY AMERICA NLS_NUMERIC_CHARACTERS ., NLS_CHARACTERSET AL32UTF8 NLS_CALENDAR GREGORIAN NLS_DATE_FORMAT DD-MON-RR NLS_DATE_LANGUAGE AMERICAN NLS_SORT BINARY NLS_TIME_FORMAT HH.MI.SSXFF AM NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR NLS_DUAL_CURRENCY $ NLS_COMP BINARY NLS_LENGTH_SEMANTICS BYTE NLS_NCHAR_CONV_EXCP FALSE NLS_NCHAR_CHARACTERSET AL16UTF16 NLS_RDBMS_VERSION 10.2.0.4.0
DBTIMEZONE is "+ 02:00".Verdi wrote:
Problem: when converting (implicit and explicit conversion with a format mask), I lose hours "00" and "00" minutes and receive something like this: "10 January 13 * 12 *. 00.00.000000000 AM.I don't think you lose necessarily any information whatsoever. It is probably more a function of your NLS_TIMESTAMP_FORMAT and NLS_DATE_FORMAT. For example, your NLS_DATE_FORMAT could be default setup for a HH24 (24 hours) which would report to midnight as hours of "00". However, it seems that your NLS_TIMESTAMP_FORMAT is configured with "HH" format with a Meridian indicator that means 12 hours time.
Your comparisons should use date/timestamp data types anyway, so as long as the input value is correctly converted to date type that shouldn't matter in any case.
You can see what is actually stored by using the DUMP function:
SQL> SELECT DUMP(TO_TIMESTAMP(TO_CHAR(TRUNC(SYSDATE,'DD'),'MM/DD/YYYY HH:MI:SS AM'))) AS TSTAMP 2 , DUMP(TRUNC(SYSDATE,'DD')) AS DT 3 FROM DUAL 4 / TSTAMP DT --------------------------------------------------------------------------- -------------------------------------------------- Typ=187 Len=20: 218,7,1,13,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0 Typ=13 Len=8: 218,7,1,13,0,0,0,0
As you can see the TSTAMP and DT store almost the same values (218,7,1,13), but the TSTAMP has more precision because of fractions of a second.
HTH!
Published by: Centinul on January 13, 2010 07:23
-
Convert a Date Format data in a different Format of Date
I'm trying to convert a date field (Text1-29), which is in the format "yyyy/mm/dd", and move it to the data in another field (text-DOB), which is in the format "mmmm dd, yyyy'."
I tried various methods, such as the following, but without success. Any suggestions?
getField("Text-DOB").value = util.scand ("mmmm dd, yyyy", (getField("Text1-29").value);)
To reformat a date string, first convert the string into a JavaScript date object and and then format this date object as needed.
Console.Show (); Console.clear();
Disable the default result field
Event.value = ";
get the string from the date of entry
var sText1_29 = this.getField('Text1-29').value;
process if there is data
If (sText1_29.toString ()! = ") {}
Console.println ("sText1_29:" + sText1_29);
convert JavaScript Date object
var oText1_29 = util.scand ("yyyy/mm/dd ', sText1_29");
Console.println ("oText1_29:" + oText1_29);
convert the object date JS to the new format
var sDOB = util.printd ("mmmm dd, yyyy', oText1_29");
Console.println ("sDOB:" + sDOB);
Event.Value = sDOB;
} -
Daylight Saving Format Date/Time String vs get time in seconds
Hi all
I have developed a real-time application using a cRIO 9074 which has two loops. The first gathers data and records the time using the module of ' string of Format Date/time ' with the following time sting: '%d/%m/%Y % H: %m ". The output is a sting with mouth/day/year hour: minute.
The second loop Gets the cRIO time using the module "get Date/Time in Seconds ' and the output of timestamp is sent by a shared variable for an application that is running on a local computer.
The problem started Sunday last with DST. With the help of MAX I am able to see that the time of cRIO is bad (1 hour less) and that him "automatically adjust clock for daylight saving time" is not checked and gray, so I am not able to change it.
The time of the first loop by using the "Date and time Format string' returns the time elapsed between the cRIO (1 hour late), however the time of the second loop is OK. I have manually corrected time using MAX, so now the first loop is correct, and the second is now over an hour.
Any ideas?
Dear RavensFan, thank you very much for your answer.
However, this was not the problem. Apparently the result with or without the element of DST is the same. I solved the problem, for now, by changing a parameter not on the function "get Date/Time in Seconds" but on the time stamp indicator.
By right clicing the indicator and go to the display Format and the advanced editing mode, I have changed the Format string to a universal time container of this: %< %="" h:="" %m="">< t="" %="" ^="">< %="" h:="" %m=""><>
Apparently the time from the 'get time in seconds' is still an hour longer, but now it is correctly displayed.
-
date/time timestamp string
Hello
I want to convert DateTime in the format string to timestamp (using Labview 7.0) format. For this that I m using scan tool chain and cable of the format string, but its not able to connect the output. I have attached the vi.
Kindly help me to fix the error
Kind regards
Ratna
-
How to convert the date in milliseconds?
Hi all
Can I know how to convert the date in milliseconds?
My current datetime like this Formate
QDateTime::currentDateTime (m:System.NET.SocketAddress.ToString ("MMMM dd, yyyy HH"))
Seconds since January 1, 1970
http://Qt-project.org/doc/Qt-4.8/QDateTime.html#toTime_t
Sinds milliseconds January 1, 1970
http://Qt-project.org/doc/Qt-4.8/QDateTime.html#toMSecsSinceEpoch
-
JSON format - Date and special characters
Hi all
I had a JSON server in which, I have a few text values and date.
- How can I convert special characters to normal String.e.g. Comma etc. ?
- How can I convert long date, a string in the format e.g. "1345670466960-0400"?
I really appreciate any help above.
Solved... Where the above closure. For others, I will post the solution.
Special characters-
QByteArray buffer(bufSize, 0); int read = reply->read(buffer.data(), available); //response = QString(buffer); -- Wrong way to convert the bytes. response = QString::fromUtf8(buffer); // right way, so special character handled itself.
Day fromatting - for example "/ Date (1345670466960-0400).
QString getStringDate(QString k){ QDateTime date = QDateTime::fromTime_t(getDate(k)); QString strDate = date.toString("MM/dd/yyyy HH:mm:ss"); return strDate; } long getDate(QString k) { long rc = 0; QString v = k; if (v.length() > 0 ) { int b = v.indexOf("/Date("); if (b >= 0) { b += 6; int e = v.indexOf(')', b); if (e > b) { QString s = v.mid(b, e); int sign = 1; if (s.indexOf('-') > 0 || s.indexOf('+') > 0) { sign = s.indexOf('-') > 0 ? -1 : 1; e = sign < 0 ? s.indexOf('-') : s.indexOf('+'); s = s.mid(0, e); } bool *ok = false; s = s.mid(0, s.length() - 3); //trimming it for seconds only.... rc = s.toLong(ok, 0); } } } return rc; }
-
Text field display [formatted] data date - different entry form.
It is probubly simple but thanks for any help. My client wants to text fields as they find tedious date drop-downs for its shape. As a result, I formatted the field to display the date as he asked mmm / d. Regardless of how the user inserts the date, it is displayed as well as the customer wants.
The problem I am facing is that when I call data for the calculations it send information in the format it was entered rather then displayed.
For example, a user can enter
1-1 and it would show [Jan / 1] in the field, but returns a string value (1-1) with this.getField. User can enter 01 jan, jan 1, jan - 1, 1-01, 01-01, ect. and it would all read correctly in the text formatted field.
I wrote a simple script to convert the month in days but it won't work unless the information is returned in the same way, it is displayed. Y at - it an easier way to convert a date text field into a variable [day of the year] regardless of how the data has been entered. (without drop downs).
Please and thanks for any help.
To get a date that you can use, use the util.scand method: http://livedocs.adobe.com/acrobat_sdk/11/Acrobat11_HTMLHelp/JS_API_AcroJS.89.1260.html
With no information of the year, it will give the current year. You'll be able to get the day and the month as and use however desired. Note that Acrobat/Reader will not let you enter an invalid date (for example, February 30) when the field is formatted as a date, if it's not a matter of concern.
-
tool to convert the data to a script
I have a list of posts with the following data
EmpNo, name, date of birth
12345, kala, August 25, 1960
23456, anugraha, 05-mar-1991
34567, marie agegee, July 1, 1984
I want to send this data to another area where the staffing table exists with the same structure.
That's why I need script like the following file
Insert in the values of staff (12345, "kala", August 25, 1960 "");
Insert in the values of staff (23456, 'anugraha','05 - mar - 1991 "");
Insert in the values of staff (34567, "marie agegee", July 1, 1984 ');
I can run this script to load data into this new personal table under different domain.
Transaction every day, I want to create this script file and store it in different domain.
Y at - it a facility to convert my data as above the script file instead of write procedures using cursors.In Oracle SQL Developer, you can right-click on a table and export data as INSERT queries, among other formats.
Thank you
-Scott-
http://sumnertechnologies.com/
http://spendolini.blogspot.com/ -
Suppose that A (col1 number) stored data 1222174057171.
Basically, this is Java. actually the date converted to number and stored in table.i want to convert in date.so how this is possible.If it's a [Java Date | http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html] then I would say to the milliseconds since January 1, 1970:
SQL> alter session set nls_date_format = 'RRRR-MM-DD HH24:MI:SS'; Session altered. SQL> SELECT DATE '1970-01-01' + NUMTODSINTERVAL(1222174057171/1000,'SECOND') dt 2 FROM dual; DT ------------------- 2008-09-23 12:47:37 SQL>
or in PL/SQL:
SQL> DECLARE 2 k_jdate_start CONSTANT DATE := DATE '1970-01-01'; 3 k_jtimestamp_start CONSTANT TIMESTAMP := TIMESTAMP '1970-01-01 00:00:00'; 4 5 v_numericdate INTEGER := 1222174057171; 6 7 v_date DATE; 8 v_timestamp TIMESTAMP; 9 BEGIN 10 v_date := k_jdate_start + NUMTODSINTERVAL(v_numericdate/1000,'SECOND'); 11 v_timestamp := k_jtimestamp_start + NUMTODSINTERVAL(v_numericdate/1000,'SECOND'); 12 13 DBMS_OUTPUT.PUT_LINE('Date: ' || v_date); 14 DBMS_OUTPUT.PUT_LINE('Timestamp: ' || v_timestamp); 15 END; 16 / Date: 2008-09-23 12:47:37 Timestamp: 23-SEP-08 12.47.37.171000 PL/SQL procedure successfully completed.
Edited by: William Robertson 26 Sep, 2008 07:21
-
Convert binary data into data across the
Hello
If I got DAQmx Read.VI binary data (analog 2D I16 Nchan Nsamp), how can I convert these data to scale?
Best,
Jay
See if that makes sense. There is probably a property for the number of bits A/d has, but I he can't think right now and can't spend toom much search time.
-
Can the Format date/timestring service that can control the execution of the loop to a VI?
Can the Format date/timestring service that can control the execution of the loop to a VI?
Example,
a VI is running at August 25, 2010 and print a txtdata(3)) '100825.
Then follow when time system running at 2359hrs, August 25, 2010 at 0000hrs, August 26, 2010.
and print a txtdata(3)) '100826.
How?
When the system changes a new date, problems occur.
-
How to connect a container ActiveX to a chain of Format Date/time control
Hello
I have an ActiveX container with the Date of Microsoft & Time inside selector object. I am trying to connect to control of the Format Date/time string. When I do that, it gives me an error saying: "You have connected a polymorphic terminal that cannot accept this type of data."
What should I do?
Kind regards.
Is that what you want to do?
-
How to insert the date with timestamp in the table values
Jin
I have a table
create the table abc1 (dob date);
insert into abc1 values (to_date (sysdate, "HH24:MI:SS RRRR/MM/DD))
but when I see in the database, it shows that the normal date without time stamp.
Is it possible to insert in the back-end with time stamp.
Thank you...Firstly, SYSDATE is a DATE already, no need to convert a DATE using the TO_DATE() function.
The date ALWAYS was a component "hour", if it is displayed until your NLS settings. for example:
SQL> CREATE TABLE ABC1(DOB DATE); Table created. SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY'; Session altered. SQL> INSERT INTO ABC1 VALUES(SYSDATE); 1 row created. SQL> SELECT * FROM ABC1; DOB ---------- 02/04/2010 SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY HH24:MI:SS'; Session altered. SQL> SELECT * FROM ABC1; DOB ------------------- 02/04/2010 12:54:57 SQL> DROP TABLE ABC1; Table dropped.
-
convert the data in the Format of Date imported from MS SQL Server.
I imported data from MS SQL Server. The column 'Date' received in digital format as 41017.6361109954. How can I convert Date in Oracle SQL.
If I import the same data in Excel and you change the Type of column to this day. He passes. But in Oracle, I tried the To_Date function with different parameters, but it did not work.
Published by: XAVER 22 April 2012 02:31select timestamp '1970-01-01 00:00:00' + numtodsinterval(41017.6361109954,'day') from dual; TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(41017.6361109954,'DAY') --------------------------------------------------------------------------- 20-APR-82 03.15.59.990002560 PM SQL>
SY.
Maybe you are looking for
-
Adobe Flash does not work with mozilla, works will be all other why e/s?
A recent update had left my computer do not leave Fire Fox on the internet, so I uninstalled and reinstalled and found out then that I had to re add it to the firewall, because he could not work. Then, when I went on she worked and loaded fine, but n
-
Satellite M40X-259: SCSI/RAID host controller
Unfortunately, I uninstalled the SCSI and RAID drivers :( Where can I download this driver for my laptop? Help me! Thank you!
-
Upgrade to Windows 10 &; option lost switchable graphics card
Sorry if this has been discussed before. I looked for a solution for the last hour, and I don't have much time today. I need to solve this problem as soon as possible. My problem was when I upgraded to Windows 10 on my laptop Windows 8.1 Y40-70. This
-
Stop command missing in xp home Task Manager menu bar
Have file, Options, display, Windows, help in the menu bar. Stop command and the menu link drop down corresponding disappeared. Another xp pro system has this command. How to repair or restore? Current running XP Home Edition SP3, recent updates to
-
Try to get a DVD to play on my old Compaq and it says missing a driver?
First time I used a DVD in this machine (before 2005). (My new machine just kaput.)He says I have DVD capability, but when I put in a disk, nothing happens. No icons appear.I went to the workstation, which shows the hard drive, but when I click it, I