Google Glass Time - time

Is there a way to get the time in Google Glass pro grammatically? I am using System.currentTimeMillis(); but it gives me a really long number such as: 1403101657961. I want the actual time that the user is looking at when he turns on Glass. Thanks.

All you need to do is create a Date object like so:
Date dt = new Date(System.currentTimeMillis());
If you want it as a formatted string you can take a look at SimpleDateFormat.

You can use the class SimpleDateFormat to format your time to Date.
Create a date with your millisec :
Date date= new Date(System.currentTimeMillis());
then format it with SDF
new SimpleDateFormat(""yyyy.MM.dd G 'at' HH:mm:ss z").format(date)

Related

How to format date string with date-fns without timezone transformation?

I have really simple date as string as ISO const mytDate = '2021-10-24T16:00:00.000Z' and I want to format it like format(new Date(myDate), 'yyyy-MM-dd HH:mm:ss') but new Date() cause that it convert it to my local timezone and I do not want it. I would like to take this string date and just format it as it is.
Is there a solution ?
Cheers!

Why date validation in Google sheets rejects today's date before 8:00am?

I've created a Google sheet to keep a list of work tasks with a column to track the date on which items are created, and built a script to automatically populate the cells in that column with the day's date when a new line is inserted.
The cell (e.g. G9) that is target of the script uses the following validation formula to make sure that when users change the date, they use a date that is neither a weekend nor in the future:
=and(isdate(G9), weekday(G9,2)<6, G9<=today())
IT ONLY WORKS BUT ONLY IF THE SCRIPT IS RUN ANYTIME AFTER 8:00am ! If I try using it any earlier the cell validation will reject the input!
The script looks like this (curRow is the number of the row that's been added):
// Adds today's date without using =today()
var myrangename = "G"+curRow;
var dateCell = sheet.getRange(myrangename);
var d = new Date();
var dateArr = [];
dateArr[0]=d.getFullYear();
dateArr[1]=d.getMonth() + 1; //Months are zero based
dateArr[2]=d.getDate();
dateCell.setValue(dateArr.join('/'));
(n.b.: I cannot use the script to simply put =today() in the cell because all the entries would change every day. )
WHY DOES IT ONLY WORK AFTER 8:00AM? Is Google somehow running on a different time zone than my computer?? I'm based in the UK, so using BST, but that shouldn't be a problem, shouldn't it...?
Try
var d = new Date();
var d = Utilities.formatDate(d, "GMT+1", "yyyy-MM-dd HH:mm:ss");
I am not sure if google would recognise BST as a time zone, but you could also try
var d = Utilities.formatDate(d, "BST", "yyyy-MM-dd HH:mm:ss");
Thank you for your suggestion, Aprillion. Turns out that a Google Sheets file has its own internal time-zone setting! which in my case was set to American Pacific time (so 8hrs behind)
(You'd think it would pick up the date and time info automatically from Windows, like other applications do!)
To set the sheet's time-zone to the correct one, you need to go to the main menu, click 'File', then 'Spreadsheet settings...', and adjust as necessary.
The script and validation now all work fine.
Thank you all for your help.

How to getHourOfDay from a timestamp using java.time?

From a java.util.Date( a timestamp), how can I get the hour of day?
In joda.time I use getHourOfDay().
There are multiple solutions for this. If you wish to use the Java 8 classes from java.time the following you need to covert a Date to one of the DateTime classes. The following can be used to convert a Date to a ZonedDateTime where you then can get the hour:
Date date = new Date();
// Convert to java 8 ZonedDateTime
Date date = new Date();
final ZonedDateTime dateTime = date.toInstant()
.atZone(ZoneId.systemDefault());
// Get the hour
int hour = dateTime.getHour();
Quite verbose as you have noticed but the simple reason for this is that a Date is sort of an Instant
Despite its name, java.util.Date represents an instant on the time-line, not a "date". The actual data stored within the object is a long count of milliseconds since 1970-01-01T00:00Z (midnight at the start of 1970 GMT/UTC).
Another approach is simply to get the field from a Calendar instance.
final Calendar instance = Calendar.getInstance();
instance.setTime(date);
final int hourOfDay = instance.get(Calendar.HOUR_OF_DAY);

updating time of datetime field using linq

I have two fields in my database for storing starttime and endtime. they are of datetime. I pick time from them using tostring("hh:mm tt"). Now I want to update only the time part of the date. I have dropdownlist to select hour and minutes and AM/PM. How can I update the time of date stored in sql server using Entity framework / LINQ in MVC3 application.
Please suggest
actually you don't really need to touch the linq part of this, basically what you want to do is just to convert the string back to a datetime object and just manipulate the datetime object by either creating a new datetime object or add/minus mm/dd/yy hours or minutes.
You must always update the whole datetime - it means you must build a new DateTime in your application and use correct Date part and defined Time part.
create new DateTime Object
DateTime mydate = New DateTime(2011, 6, 1, 12, 30, 0);
or
DateTime mydate = DateTime.Parse("2011-06-1 12:30:00 PM");

retrieve oracle database Date column in java using Calendar Instance and compare with today's date

I have Oracle database with Date column in it and I want to retrieve it from recordset using Calendar since I want to compare it with today's date which is built using Calendar.
Not really sure what you meant with retrieving the date "using Calendar", but if you are using Java, and want to read a date from database and compare it with today's date, it goes like this:
java.sql.Date dbDate = resultset.getDate("dateField");
java.util.Date date = new Date(dbDate.getTime());
Calendar calendar = Calendar.getInstance();
java.util.Date today = calendar.getTime(); // "today = new Date();" would work just as well
if (date.before(today)) {
// do something
} else if (date.after(today)) {
// do something else
}

Resources