Is it possible to have datepicker land on todays date when the app starts?
currently my app shows no values on start up and only when I start changing the date in my datepicker then values start appearing. datepicker outputs values to labels
Which programming language do you use?
This code is for swift3 ;
You should write it in viewDidLoad()
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
yourTextField.text = dateFormatter.string(from: (NSDate() as Date))
Related
I am developing an application with Kony Platform. I need to use a Calendar widget wherein I need to restrict selection of future dates. Is it possible? If yes, then how?
You need to set validEndDate properties as current date for the calendar widget. Please find the Same code
var mydate = new Date();
var currDate =[mydate.getDate(), mydate.getMonth() + 1, mydate.getFullYear()];
frmlanding.cal1.validEndDate = currDate;
Making a countdown app and instead of manually adding the due date i want to be able to do it with a date picker.
Here is the code i am using now. What i need help with is implementing code that let's me do this by using the date picker (The competitionDate).
// Here we set the current date
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Hour, .Minute, .Second, .Nanosecond], fromDate: date)
let hour = components.hour
let minutes = components.minute
let month = components.month
let year = components.year
let day = components.day
let currentDate = calendar.dateFromComponents(components)
// here we set the due date. When the timer is supposed to finish
// final Calendar value
let userCalendar = NSCalendar.currentCalendar()
let competitionDate = NSDateComponents()
competitionDate.year = 2015
competitionDate.month = 6
competitionDate.day = 21
competitionDate.hour = 08
competitionDate.minute = 00
let competitionDay = userCalendar.dateFromComponents(competitionDate)!
// Here we compare the two dates
competitionDay.timeIntervalSinceDate(currentDate!)
let dayCalendarUnit = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Hour, NSCalendarUnit.Minute], fromDate: date)
you mean to get the date of the date picker?
you can do it like so:
let date:NSDate = datePicker.date
I have one kind of scenario using date picker. I have date picker with max date=current date + 10 days,on page load only i want to show date more than the max date,but I'm allowing user to enter only up to max date. Is it possible. Without looking maxing date i want to display only the date what ever i want.code:-
var datepicker = $("#date" + uid).data("kendoDatePicker");
var addDays = new Date();
if (arr[1] == "") {
var d = new Date();
datepicker.min(new Date());
datepicker.max(new Date(d.getDate() , d.getMonth(), d.getDate()+ parseInt(arr[1]) - parseInt(1)));
}
I don't know if this is achievable. But what if you try to add two date pickers instead? One that display only the text, and the other only the calendar button. You need to play a bit the CSS, but I think it could spare you a lot of time.
How can I make the date picker show the date and time that is now? Without clicking nothing, just at the beginning. I am very new in Cocoa, I would appreciate any orientation.
This is what I have done:
- I create a new project > OSX > Application > Cocoa Application
- Main.storyboard. Drag a Date Picker
- Ctrl + drag from date picker to ViewController.swift. I give it the name datePicker: #IBOutlet weak var datePicker: NSDatePicker!
Add [datePicker setDateValue:[NSDate new]]; in viewdidLoad of View Controller
Here is a function that returns the hour and the day and corrects for different time zones, I am using 7 for Nevada PST time zone but you can update for your specific state
func returnHourDay() -> (Int, Int) {
let dateNow = Date()
let calendar = Calendar.current
var Hour = (calendar as NSCalendar).component(NSCalendar.Unit.hour, from: dateNow)
let Day = (calendar as NSCalendar).component(NSCalendar.Unit.weekday, from: dateNow)
//correct for specific time zones
func ltzOffset() -> Int { return NSTimeZone.local.secondsFromGMT() }
let hourOffset = 7 + ltzOffset()/60/60 //0 for Nevada 7 - 7 = 0
Hour = Hour+hourOffset
return (Hour, Day)
}
I don't know how to show Time in AM/PM format in blackberry using blackberry datefield.Pls give me a idea how to do this.
Use SimpleDateFormat:
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss aa");
long date = System.currentTimeMillis();
DateField dateField = new DateField("time:", date, timeFormat);
add(dateField);
alt text http://img171.imageshack.us/img171/7642/timeformat.jpg