i work with swift 3 for macOS and would like to save my date picker value in core data.
I have an attribute (type date) in my entity.
I tried this code for save my date picker value into core date:
let entity = NSEntityDescription.entity(forEntityName: "Person", in: context)
let newRecord = NSManagedObject(entity: entity!, insertInto: context) as! Person
newRecord.bday = myDatePicker.dateValue as NSDate
This value will be save in CoreData:
517935600
is this correct? oO
Probably. It depends on what date you had selected in the date picker. NSDate and Date store the date as the number of seconds since a reference date, which is the start of January 1, 2000 UTC. It looks like the UTC value from your date picker was May 31 2017 at 9:00 UTC.
Related
I am storing a date in mongodb using mongose with the help of moment js.
I am creating the date object from a date string which is in the format MM/DD/YYYY.
below is how i assign the date
const startDate = momentTz(
data.startDate,
"MM/DD/YYYY",
"Asia/Kolkata"
).startOf("day");
but ever time I assign this date object to the mongoose model while creating a document it is storing as 2022-11-30T18:30:00.000+00:00 ie, the time is being automatically set to 18:30.
how can i set this to the start of the day.
Use this one:
const startDate = momentTz(
data.startDate,
"MM/DD/YYYY",
"Asia/Kolkata"
).startOf("day").toDate();
MongoDB stores Date values as UTC times - always and only. It is the client responsibility to display the date/time in local time zone and format.
MongoDB stores dates as BSON type 9, which stores the number of milliseconds since 1970-01-01 00:00 UTC.
18:30 UTC is midnight in Kolkata, so that date/time is correctly showing the start of the day 2022-11-31 IST.
It is up to the client program to convert from UTC to a different timezone if that is desired.
In Suitescript 2.0, I can able to get record by id.
RESTlet:
var response = record.load({
type: resourceType,
id: context.recordId
});
Response:
{
...
"starttime": "6:00 pm",
"startdate": "13 FEBRUARY, 2019"
...
}
How to get all date & time values as millisecs in Netsuite using suitescript 2.0?
NetSuite has 2 types of date fields, date and dateTime.
Date field does not contain time details, so you cannot get time from these fields like trandate etc. Whereas if you use getValue on dateTime field, NetSuite returns a date object and you can toISOString or any other method from Date class.
i would like to know how to structure a timestamp field in Firestore in order to do specific queries like:
Get all the documents with the same hour in a month
Retrieve timestamp from firebase and compare with required hour.If document matches add the document to an array.Finally after comparing with all documents your array contains only documents with same hour in a month
Date month = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(month.getTime());
calendar.add(Calendar.MONTH, -6);
final String date = String.valueOf(document.get("OrderPlacedDateTime"));
if(date.contains((CharSequence) year)) {
//add to array
}
I did this in android idea might be helpful.
I stored date in database but whenever i am fetching then its format change
getting date - 2018-07-31T06:48:01.649Z
stored date in db - 2018-07-31 12:18:01.649
here is my code
var timee = result.created;
By default, dates are stored in UTC in MongoDB so you are seeing the difference in the time zone of stored and retrieved dates.
new Date() returns the current date as a Date object. The mongo shell wraps the Date object with the ISODate helper. The ISODate is in UTC.
You can read the MongoDB specification here.
There are several approaches that you can apply. Either convert the date to UTC timezone before saving it or convert into locale time zone after loading the date.
new Date(ISODate().toString() + 'UTC')
ISODate("2018-08-01T11:39:39Z")
and to replace the T and Z with an empty space using the javascript.
dateString.replace("T", " ").replace("Z", " ");
In my Grails project I have a date in the controller and I need to increment this date by one month, so I did as below:
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD HH:MM:ss");
def temp
use (TimeCategory)
{
temp=new Date()+30.days//current date 6-1-2016
}
println(sdf.format(temp))
this was the output:
2016-02-36
I tried plus(30) also giving me the same result. Is there a way to do this increment correctly?
In a Java date format, D stands for "Day in Year", hence 6+30 = 36. You want to use d for "Day in month".
You are also using Y which is "Week year" instead of y which is "year" and M for minutes when you want m.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
I'd go with this approach :
Calendar calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, 30)
or another approach is to use Joda Time