How to get time in AM and PM from a DateTime String in Android from a .vcs file - utc

I am parsing a .vcs file and it just has the date-time in the below format. For example-The start date-time of the event is in the below format:
DTSTART:20000803T103000Z
Since I have this string I can easily find out the values of hour, mins, day, month , year etc. and display it easily in readable format.
But I want to show AM and PM also with time. How can I do this?
Which Android function can I use to get AM and PM from this string.
Any help would be appreciated.

hour = StartDate.substring(9,11);
minutes= StartDate.substring(11,13);
hoursofday = Integer.parseInt(hour);
minutesofday = Integer.parseInt(minutes);
if(hourOfDay>12)
{
datehid.setText(String.valueOf(hourOfDay-12)+ ":"+(String.valueOf(minute)+"pm"));
}
if(hourOfDay==12)
{
datehid.setText("12"+ ":"+(String.valueOf(minute)+"pm"));
}
if(hourOfDay<12)
{
datehid.setText(String.valueOf(hourOfDay)+ ":"+(String.valueOf(minute)+"am"));
}

Related

Compare Dates in Kotlin

How can i compare Dates in Kotlin?
I have the Date of an Event as a String (Format:dd/mm/yy) and I want to check if it is within the next 7 Days of the current Date.
The time in this case is not relevant or if needet I would use midnight.
Can someone please help me with this?
In my current code i got both Dates by this:
val date = document.data["Date"].toString() //Example: 22/08/22 (dd/MM/yy)
val today = SimpleDateFormat("dd/MM/yy").format(Date()).toString()
this is within a Android environment.
I can't get the date more specific because i am getting it from a Database.
Parse string into LocalDate using its parse method. There’s no out-of-the-box DateTimeFormatter for dd/mm/yy format, but you can trivially create one using DateTimeFormatter.ofPattern.
Get current date using LocalDate.now().
diff = ChronoUnit.DAYS.between(now, date1)

How to fix for getting wrong date while change the time zone in react native?

I'm using new Date("2017-01-12") for string to date conversion. Its working fine for IST, If I change the device time zone like Chicago(CST), then the date shows as previous date. Because CST is GMT-0600 so it reduces -6 hours and shows previous day date("2017-01-11"). Any other way to convert the date string to date using Moment?
Date(year, month, day) is the valid constructor here.
2 things to know, when you pass the month it starts in 0, so if you pass January it is the month 0, don't to confuse with 1.
Then if you have a string format date like YYYY-MM-YY you have to do this supposing that your string is named stringDate:
var stringDateSplited = stringDate.split('-');
var dateResult = new Date(stringDateSplited[0], (stringDateSplited[1] -1) , stringDateSplited[2]);
This could be the result you want!

How to Change the date format yyyy/MM/dd HH:mm:ss to dd_mm_yy through modified java script value in pentaho

How to Change the date format yyyy/MM/dd HH:mm:ss to dd_mm_yy through modified java script value in pentaho?
Use this function in Modified Java Script Value step:
date2str(input, "dd_MM_yy");
You can use the SELECT step, and then in the Meta Data Tab, you can select the datatype as DATE and then use the format as "dd_MM_yy"
That's it, pretty simple :)
In pentaho a Date has always the time. There is not such thing as only date.
So, my guess would be that you need to format on output, converting it to a string for example.
But, if what you need is the date without the time, and by this i mean "yyyy/mm/dd 00:00:00", you can get it like this in Javascript:
var dateFieldValue=<yourdatecolumn>;
var year = dateFieldValue.getYear()+1900;
var month = dateFieldValue.getMonth();
var day = dateFieldValue.getDate();
var dateOnly = new Date(year,month,day);
or the last line could be:
var dateOnly = year + '-' + (month+1) + '-' + day;
if you want a String output like 'yyyy-mm-dd'
Hope this helps.

Calculating difference between time now and scheduledstart crm c#

How can i calculate difference between the time now and the "scheduledstart" field (in appointment entity) and put the value into another number field ("el_early_cancel_notice" - like duration field).
This is what i wrote untill now but i don't know how to proceed. Can someone help?
if ((serviceAppontment.Attributes.Contains("scheduledstart")) && (serviceAppontment.Attributes["scheduledstart"] != null) && (TimeNow > SchelStart))
{
throw new InvalidPluginExecutionException(serviceAppontment.Attributes["scheduledstart"].ToString());
try
{
//here i need to calculate the difference and i don't know where to begin...
}
DateTime startDate = (DateTime)serviceAppontment["scheduledstart"];
TimeSpan diff = DateTime.UtcNow - startDate;
serviceAppointment["el_early_cancel_notice"] = diff.Days;
localContext.OrganizationService.Update(serviceAppoinment);
Because DateTime is stored in UTC format in CRM, you need to deal with DateTime in UTC. And I assume you want duration in days. More about TimeSpan here.
Good luck!
1) Cast your field to a date time:
DateTime startDate = (DateTime)serviceAppontment.Attributes["scheduledstart"];
2) Use one of these methods to get a TimeSpan.
3) Update your el_early_cancel_notice field with information from the TimeSpan:
serviceAppontment.Attributes["el_early_cancel_notice"] = [Appropriate number from TimeSpan];

Is there any way to Indentify the Time if it comes 12 Hour format without AM/PM?

I am getting date from web service in 12 hour Format like this #"2012-11-23 04:46:19.120". Is there any way to identify weather this time is AM or PM? Please guide me what should I do to get the correct result?
I am getting Dictionary in Response like this:
{
address = "22 W 46th St,\nNew York,New York,10036";
"business_name" = "Monster Sushi Midtown";
"con_res_id" = 5940;
"current_date" = "2012-11-23 04:46:19.120";
"deal_description" = "Enjoy Happy Hour with $3 Large Beers & $2 Regular Beers";
}
Thanks iosRider for your question and providing some informations.
The answer is NO.
If your database is not storing the AM / PM, cocoa cant convert it into AM or PM.
Now what you can do is :
Discard the timestamp from both the dates, store it in NSString and compare !!!
no, if the date format of the response is a 12 hours format and do not include the AM/PM value there is no way to infer it.