Getting date as string - need to convert - apache-flex

Programming in Flex 4.5
I'm getting a date as a String.
I don't know what date or hour I'm getting.
I want to convert the string to date and take only the hours & minutes.
For example:
Getting - "2012-02-07T13:35:46+02:00"
I want to see: 13:35.
Suggestions or any other solutions?
After some digging, Solution:
var myDate:Date;
myDate = DateFormmater.parseDateString(myDateString);
var dateResult:String = myDate.getHours() + ":" + myDate.getMinutes();
Thanks anyway! :-)!

You can to use date.getHours() and date.getMinutes(). Try the following:
var d:Date = DateField.stringToDate("your_date_string","YYYY-MM-DD");
trace("hours: ", date.getHours()); // returns 13
trace("minutes: ", date.getMinutes()); // returns 35

private function init():void
{
var isoStr:String = "2012-02-07T13:35:46+02:00";
var d:Date = new Date;
d = isoToDate(isoStr)
trace(d.hours);
}
private function isoToDate(value:String):Date
{
var dateStr:String = value;
dateStr = dateStr.replace(/\-/g, "/");
dateStr = dateStr.replace("T", " ");
dateStr = dateStr.replace("+02:00", " GMT-0000");
return new Date(Date.parse(dateStr));
}

I see you've already got the answer, but for future users, here it is.
var myDateString:String="2012-02-07T13:35:46+02:00"
//This is of the format <yyyy-mm-dd>T<hh:mm:ss><UTC-OFFSET AS hh:mm>
//You could write your own function to parse it, or use Flex's DateFormatter class
var myDate:Date=DateFormatter.parseDateString(myDateString);
//Now, myDate has the date as a Flex Date type.
//You can use the various date functions. In this case,
trace(myDate.getHours()); //Traces the hh value
trace(myDate.getMinutes()); //Traces the mm value

Related

how to make double from string

My user never value to a pop up and I add .0 at the end however once I convert the value to double the value is edited to only 2 and I need the value 2.0
if (pResult.Ok && !string.IsNullOrWhiteSpace(pResult.Text))
{
var test = pResult.Text + ".0";
double doub = Convert.ToDouble(test);
_settingsService.TimeOutIdentification = doub;
}
Please use following code to convert it
string str1 = String.Format("{0:F}", test);

How to find difference between two times in 24 hour format - Flutter?

I have to find the difference between two times in 24 hour format. I have the two time strings, Eg: 10:40 and 18:20. How can I find the difference between these two times in Flutter?
You can use intl package.
var format = DateFormat("HH:mm");
var one = format.parse("10:40");
var two = format.parse("18:20");
print("${two.difference(one)}"); // prints 7:40
A complete answer for perfect calculation is given bellow
String start_time = formateTime('12:00'); // or if '24:00'
String end_time = formateTime('24:00'); // or if '12:00
var format = DateFormat("HH:mm");
var start = format.parse(start_time);
var end = format.parse(end_time);
if (start.isAfter(end)) {
print('start is big');
print('difference = ${start.difference(end)}');
} else if(start.isBefore(end)){
print('end is big');
print('difference = ${end.difference(start)}');
}else{
print('difference = ${end.difference(start)}');
}

Using getTime in a For loop in google sheets script

I am trying to run a 'for' loop that looks like this:
function runMultipleDates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//9/26/2018 is 1569477600000 and 2/28/2019 is 1551337200000; 9/21/2018 is 1537509600000
for (var date1 = 1537596000000 /*9/21/2018*/; date1 < 1569477600000 /*9/26/2018*/; date1 +=86400000) {
//runEverything();
var date2 = new Date();
date2 = date2.setTime(date1);
ss.getSheetByName('Time Range').getRange("A3").setValue(date2);
};
};
My goal is to run a function called "runEverything()" that reference a date located in cell A3 of a sheet called 'Time Range'. As long as the date in cell A3 is less that 9/26/2018, the for loop should run my function 'runEverything' and then set a new date in A3. When I do my test loop, the setValue(date2) returns a numeric value rather than a date in that cell (A3). Can someone point out how I can return the date format rather than the numeric value of date? if there is a more elegant way to achieve this, I am all ears!
Thank you for your insight!
You want to use the date string instead of the unix time
If my understanding is correct, how about the following script? Please think of this as just one of several possible answers.
Sample script:
function runMultipleDates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var start = new Date("2018-09-29"); // <--- 1538200800000
var end = new Date("2018-10-05"); // <--- 1538719200000
var step = 1; // 1 day (86400000)
for (var date1 = start; date1 <= end; date1.setDate(date1.getDate() + step)) {
runEverything();
var date2 = new Date(date1.getTime());
date2.setDate(date2.getDate() + 1);
ss.getSheetByName('Time Range').getRange("A3").setValue(date2);
};
}
This script brings the same result with the script of your answer.
When the script is run, 10/06/2018 is put to the cell "A3".
References:
getDate()
setDate()
Tanaike suggested using new Date(date2) in the setValue() and it worked. My final script is something like this:
function runMultipleDates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
for (var date1 = 1538200800000 ; date1 <= 1538719200000; date1 +=86400000) {
runEverything();
var date2 = new Date();
date2 = date2.setTime(date1+86400000);
ss.getSheetByName('Time Range').getRange("A3").setValue(new Date(date2));
};

dealing with a null date field

I have a date field on an XPage, this control may contain a date or be blank. In a repeat control I have this code:
var doc:NotesDocument = detailData.getDocument();
var sDate = doc.getItemValue("ACAutoStart");
doc.recycle()
return "Start Date = " + sDate
If ACAutoStart contains a date then it is displayed as [10/10/2013 12:34:15 AM MDT] if it is blank it displays as []. As I understand it the [] indicates that the result is an array but if I try using sDate[0] there is an error. I can't use getItemValueDateTime as it does not like the null return. How do I get this into a simple string value?
Replace your last line with return "Start Date = " + sDate.firstElement().
doc.getItemValue() returns an object of class java.util.Vector. As it is not an Array you get the first element with firstElement() instead of [0] .
UPDATE:
As you mentioned in your comment it has to work also for empty values and you added try:
var sDate = "";
try {sDate = doc.getItemValue("ACAutoStart").firstElement()} catch (e) {};
return "Start Date = " + sDate
...just as another way (returns converted NotesDateTime to Date):
function getJavaDateData(doc:NotesDocument, field:string)
{
var item:NotesItem = doc.getFirstItem(field);
if (item != null){
var dt:NotesDateTime = item.getDateTimeValue();
if (dt != null){
return dt.toJavaDate();
}
}
return null;
}
Off-course need to be adapted for your logic...

How to get the Current Date Time Formatted in Flex

I'm trying to get the current date time in Flex/AIR?
To get the current date time, just create a new Date object with no values into the constructor, like this:
var CurrentDateTime:Date = new Date();
Formatting it depends on how you want to format it; here is one option:
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var CurrentDF:DateFormatter = new DateFormatter();
CurrentDF.formatString = "MM/DD/YY LL:NN:SS A"
var DateTimeString:String = CurrentDF.format(CurrentDateTime);
return DateTimeString;
}
currentTime = new Date();
From : http://livedocs.adobe.com/flex/3/html/help.html?content=08_Dates_and_times_5.html
and
http://docs.huihoo.com/flex/4/Date.html
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var DateString:String = CurrentDateTime.getMonth().toString()+ "/"+CurrentDateTime.getDate().toString() +"/"+CurrentDateTime.getFullYear().toString();
var TimeString:String = CurrentDateTime.getHours().toString()+ ":"+ doubleDigitFormat(CurrentDateTime.getMinutes());
var DateTimeString:String = DateString + " " + TimeString;
return DateTimeString;
}
function doubleDigitFormat(num:uint):String
{
if(num < 10) {
return ("0" + num);
}
return num.toString();
}

Resources