TimeZone Example in Flex? - apache-flex

Actually in my Flex Application i'm passing Date(in String format) as well as Timezone(String format) convert into Date type but it is not converting Date type ... it is giving null value and my
sample code like this...
var tzDate:String="20012-12-12";
var tzString:String=tzComboBox.selectedItem;//hear value GMT+0530
var startDate:Date = DateField.stringToDate(tzDate+" "+tzString,"YYYY-MM-DD TZD");
Alert.show(startDate);//hear value giving "Null"
The problem is it's not converting Date format...Plz Help me

use parse function and format date before parsing
var tzDate:String="2012-12-12";
var tzString:String="GMT+0530";
var dateformat:DateFormatter = new DateFormatter();
dateformat.formatString = "YYYY/MM/DD";
var dateStr:String = dateformat.format(tzDate) +" "+ tzString;
//dateStr is 2012/12/12 GMT+0530
var startDate:Date = new Date(Date.parse(dateStr));
Alert.show(startDate.toString());
//Show Date of Local time Zone
//Tue Dec 11 21:30:00 GMT+0300 2012
Hopes that Helps

Related

Invalid Date in moment.js datetime addition

I want to add time/duration in HH:mm(eg 00:10) to a Date time in format MM-DD-YYYY HH:MM
I have date and time in 2 separate objects so am trying the below
var plannedStartDate = document.getElementById("date1"); //eg 02-12-2020
var plannedStartTime = document.getElementById("plannedStart1"); //eg 09:00
var plannedStartDateTime = moment(plannedStartDate.value + " " + plannedStartTime.value);
var minutes = $("#duration1").text().split(':')[1];
var hours = $("#duration1").text().split(':')[0];
var date = plannedStartDateTime.add(hours, 'hours').add(minutes, 'minutes').format("MM-DD-YYYY HH:mm");
console.log("Final:"+date); //gives invalid date
What am I doing wrong
Check this working sandbox: https://codesandbox.io/s/compassionate-bas-fg1c2
It adds the hours and minutes to the input date and then prints in a given format
var moment = require("moment");
var input = "2020-02-12";
var hoursMinutes = "9:10";
var hours = hoursMinutes.split(":")[0];
var minutes = hoursMinutes.split(":")[1];
var momentInTime = moment(input)
.add(hours, "hours")
.add(minutes, "minutes");
var converted = moment(momentInTime).format("DD-MM-YYYY HH:mm:ss");
console.log(converted);

Dart - Convert time from dd/MM/YYYY to YYYY-MM-dd

How to convert a date from dd/MM/YYYY to YYYY-MM-dd
Example: convert from 08/11/2019 to 2019-11-08
I tried the following code but got the
Invalid date format 08/11/2019 exception
import 'package:intl/intl.dart';
DateFormat('YYYY-MM-dd').format(DateTime.parse('08.11.2019'));
var inputFormat = DateFormat('dd/MM/yyyy');
var date1 = inputFormat.parse('18/08/2019');
var outputFormat = DateFormat('yyyy-MM-dd');
var date2 = outputFormat.format(date1); // 2019-08-18
Or you can use String
var date2String = outputFormat.format(date1); // "2019-08-18"
Try using this package, Jiffy. It is inspired by momentjs.
This can be solved in one line
var dateTime = Jiffy("18/08/2019", "dd/MM/yyyy").format("yyyy-MM-dd"); // 2019-08-18
You can also format it with default formats
var dateTime = Jiffy("18/08/2019", "dd/MM/yyyy").yMMMMd; // August 18, 2019

Code to parse a local date, time, and timezone into a UTC string with Moment.js

In separate fields, I collect DisplayDate, DisplayTime, and TimeZone from the user. I want to put those into a moment and output the UTC formatted string to save into a hidden field that gets sent back to the server. I used the below code, but it uses the local timezone, rather than the selected TimeZone I entered. How do I get it to observe selTimeZonesVal?
var startTime = $('#StartTime');
var displayDateVal = $('#DisplayDate').val();
var displayTimeVal = $('#DisplayTime').val();
var selTimeZonesVal = $('#TimeZones').val();
var dtMoment = moment(displayDateVal + ' ' + displayTimeVal).tz(selTimeZonesVal);
var formattedUtc = dtMoment.utc().format('YYYY-MM-DDTHH:mm:ss');
startTime.val(formattedUtc);
The problem was with the date parsing. Somehow, moment was able to parse the date, but it would ignore the timezone if the date wasn't in ISO format.
The fix:
var startTime = $('#StartTimeUtc');
var displayDateVal = $('#DisplayDate').val();
var displayTimeVal = $('#DisplayTime').val();
var selTimeZonesVal = $('#TimeZones').val();
// Massage the date so moment can parse it (moment doesn't like mm/dd/yyyy)
var localDT = new Date(displayDateVal + ' ' + displayTimeVal);
var parseDT = moment(localDT).format('YYYY-MM-DDTHH:mm:ss')
var dtMoment = moment.tz(parseDT, selTimeZonesVal);
var formattedUtc = dtMoment.utc().format('YYYY-MM-DDTHH:mm:ss');
startTime.val(formattedUtc);

Formatting Date in Spreadsheet

I have a column in spreadsheet that is 'date'.
When I retrieve the date with the following code,
for (var i = 1; i < data.length; ++i) {
var row = data[i];
var date= row[0];
Logger.log(date);
I get
Wed Nov 12 2014 00:00:00 GMT+0800 (HKT)
Is there a way to just show the output as
Wed Oct 15 2014
I tried converting to JSON since it is an object, so that I can use substring
startDate = JSON.stringify(startDate);
startDate = startDate.substring(0, 14);
But it doesn't output correctly.
"2014-11-12T16:00:00.000Z"
Use formatDate() from the "Utilities" class:
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)
Did you try using "formatDate" in Utilities class
formatDate(date, timeZone, format)
try doing this:
var dateToFormat = row[0];
var formattedDate = Utilities.formatDate(new Date(dateToFormat), "GMT", "EEE, MMM d, yyyy");
Logger.log(formattedDate);

Getting date as string - need to convert

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

Resources