Converting German Time Format to English Format - time

Good morning together,
I have an app with iOS 9 and Swift 2
At the moment, my app is in German language.
My goal is: I will translate it in English.
This works good, but I have a problem with my time format.
At the moment, I use a 24 time format like this:
09:00 Uhr
17:00 Uhr
23:00 Uhr
...
Is there a quick way to convert this in the English 12h format, like this:
09:00 Uhr => 09:00 AM
17:00 Uhr => 05:00 PM
23:00 Uhr => 11:00 PM
...
Thank you very much.

You could use NSDateFormatter to modify
let formatter = NSDateFormatter()
formatter.dateFormat = "HH:mm"
let date = formatter.dateFromString(yourString)
formatter.dateFormat = "hh:mm AA"
let result = formatter.stringFromDate(date)
You my propably need to get rid of the "Uhr" before (you can replace " Uhr" with "")

Try this one, it should do exactly what you want:
let date = NSDate()
let dateFormetter = NSDateFormatter()
dateFormetter.dateFormat = "h:mm a"
dateFormetter.timeZone = NSTimeZone(name: "UTC")
dateFormetter.locale = NSLocale(localeIdentifier: "en_GB")
let timeString = dateFormetter.stringFromDate(date) // 7:34 a.m.

As per the other two answers, use NSDateFormatter:
let dateFormatIn = NSDateFormatter()
let dateFormatOut = NSDateFormatter()
dateFormatIn.dateFormat = "HH:mm 'Uhr'"
dateFormatOut.dateFormat = "hh:mm a"
dateFormatOut.locale = NSLocale(localeIdentifier: "en_US")
var str = "07:00 Uhr"
func convertTimeRepresentation(str: String) -> String? {
if let n = dateFormatIn.dateFromString(str) {
return dateFormatOut.stringFromDate(n)
}
return nil
}
convertTimeRepresentation(str)

Related

How to split date and time from a string like 8/29/2011 1:00 PM in laravel

in my blade there is a DateTime picker which selects in mm/dd/yyyy hh:mm AM/PM format. and i need to extract this to date = 8/29/2011 and time = 13:00 .
how can I do that?
Do as below.
$stringdate = "8/29/2011 1:00 PM";
$timestemp = strtotime($stringdate);
$date = date('Y-m-d', $timestemp);
$time = date('H:i:s',$timestemp);
echo $date;
echo $time;
check example
Edit:- as you want this format YYYY-MM-DD hh:mm
$datetime = date('Y-m-d H:i', strtotime("8/29/2011 1:00 PM"));
echo $datetime; //output "2011-08-29 13:00";
Try this way.
#php
$input = '2017-06-27 12:58:20';
$format1 = 'Y-m-d';
$format2 = 'H:i:s';
$date = Carbon\Carbon::parse($input)->format($format1);
$time = Carbon\Carbon::parse($input)->format($format2);
#endphp
It is simple just try it
$date="8/29/2011 1:00 PM"; // date that get from view (blade page)
$createTimestamp = new DateTime($date); // create timestamp object from string
$date = $createTimestamp->format('m/d/Y'); // get date
$time = $createTimestamp->format('H:i:s A'); // get time with AM/PM format
return "date: ".$date." time: ".$time; // return your result
Try this way
Use Carbon;
$dateAndTime=Carbon::parse('8/29/2011 1:00 PM');
$date=$dateAndTime->format('d-m-Y');// 29-8-2011
$time=$dateAndTime->format('H:i:s');// 1:00
$time=$dateAndTime->format('H:i:s A');// 1:00 AM/PM
Refer this link to understand more about Carbon.

Put Time without Date in a Cell Jxl

I want to put the time on a cell. Here is the code I have so far:
DateFormat valueFormatDate = new DateFormat("HH:mm");
valueFormatDate.getDateFormat().setTimeZone( TimeZone.getTimeZone("Europe/Paris"));
WritableCellFormat formatDate = new WritableCellFormat(valueFormatDate);
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
DateTime dt=new DateTime( 1, j+1,( java.util.Date )(formatter.parse(table.getValueAt(j, 1).toString())) ,formatDate); s.addCell(dt);
My Problem is, that the date is displayed too. How can I only display the time?
Try this, worked for me.
SimpleDateFormat fmt = new SimpleDateFormat("hh:mm:ss",new Locale("fr","FR"));
sheet.addCell(new Label(1,1, "Time: " + fmt.format(new Date())));

Swift timeInterval formatter

I can get the date in de date picker, calculate the time left and put in a label. This gives seconds:
let timeLeft = datePicker.dateValue.timeIntervalSinceNow
countingLabel.stringValue = "seconds left: \(timeLeft)"
How to format "timeLeft"?
I tried this and it does not work:
var formatter = NSDateFormatter()
formatter.dateFormat = "EEEE, yyyy-MM-dd hh:mm:ss"
let timeLeft2 = formatter.stringFromDate(timeLeft)
You can use NSDateComponentsFormatter. From the
documentation:
An NSDateComponentsFormatter object takes quantities of time and
formats them as a user-readable string. Use a date components
formatter to create strings for your app’s interface.
Example:
let formatter = NSDateComponentsFormatter()
formatter.unitsStyle = .Full
formatter.allowedUnits = .CalendarUnitSecond | .CalendarUnitMinute | .CalendarUnitHour
let pickedDate = datePicker.dateValue
let now = NSDate()
let formattedTimeLeft = formatter.stringFromDate(now, toDate: pickedDate)!
// Example result : 1:06:50
There are some more output formats available, e.g.
.Abbreviated : 1h 6m 50s
.Short : 1 hr, 6 min, 50 secs
.Full : 1 hour, 6 minutes and 50 seconds
Update for Swift 4 and later:
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full // or .short or .abbreviated
formatter.allowedUnits = [.second, .minute, .hour]
let pickedDate = datePicker.date
let now = Date()
let formattedTimeLeft = formatter.string(from: now, to: pickedDate)!
To get timeLeft you should use two time components and get their differnece as follow:
let todayComponents = NSCalendar.currentCalendar().components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | , fromDate : NSDate())
var pickedDateComponents = NSCalendar.currentCalendar().components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | , fromDate : datePicker.dateValue)
pickedDateComponents.second = pickedDateComponents.second - todayComponents.second
pickedDateComponents.minute = pickedDateComponents.minute - todayComponents.minute
pickedDateComponents.hour = pickedDateComponents.hour - todayComponents.hour
pickedDateComponents.day =pickedDateComponents.day - todayComponents.day
pickedDateComponents.month = pickedDateComponents.month - todayComponents.month
pickedDateComponents.year = pickedDateComponents.year - todayComponents.year
let timeLeft = NSCalendar.currentCalendar().dateFromComponents(pickedDateComponents)!

Creating Bi-weekly appointment in Outlook

I'm trying to create a bi-weekly appointment using vbscript. But for some reason the output date is always occurring on every other Thursday when it should be every other Friday. I have outlook set up to start the week on a Sunday. I have changed and removed.DayOfWeekMask and it stays on Thursdays.
Dim endDate
Dim startDate
endDate = #01/01/2022#
startDate = #01/01/2012#
Const olRecursBiWeekly = 1
Const olFriday = 6
Set olkEvent = olkApp.CreateItem(1)
olkEvent.Subject = "Pay Day"
olkEvent.AllDayEvent = True
olkEvent.ReminderSet = False
Set objRecurrence = olkEvent.GetRecurrencePattern
objRecurrence.DayOfWeekMask = olFriday
objRecurrence.RecurrenceType = olRecursBiWeekly
objRecurrence.PatternStartDate = startDate
objRecurrence.Interval = 2
objRecurrence.PatternEndDate = endDate
olkEvent.Save
Thanks for your help.
There no such thing is olRecursBiWeekly. You need olRecursWeekly (=1).
olFriday is &H20 (32 decimal).
You need to move things around:
The DayOfWeekMask should be set after the RecurrenceType property has
been set and before the PatternEndDate and PatternStartDate properties
are set.
From MSDN

Retrieving date format with am/pm in codeigniter

I have converted date to my local time as below:
$this->date_string = "%Y/%m/%d %h:%i:%s";
$timestamp = now();
$timezone = 'UP45';
$daylight_saving = TRUE;
$time = gmt_to_local($timestamp, $timezone, $daylight_saving);
$this->updated_date = mdate($this->date_string,$time);
And I'm storing this field in to database.
Now at retrieval time I want format like this:
"11-04-2011 4:50:00 PM"
I have used this code:
$timestamp = strtotime($rs->updated_date);
$date1 = "%d-%m-%Y %h:%i:%s %a";
$updat1 = date($date1,$timestamp);
But this will give me only
"11-04-2011 4:50:00 AM"
But I have stored it like it was PM.
Might get voted down, but will have a go at it.
Is it because the MySQL stores it in 24 hour format? (assuming you are using the datetime field type)
Maybe this will help
Converting mysql TIME from 24 HR to AM/PM format
sorry if it doesn't.

Resources